Jackson Serialize对象在Java WS中为空
我有一个POJO:Jackson Serialize对象在Java WS中为空,java,json,jackson,Java,Json,Jackson,我有一个POJO: public class Step implements IStep { String identifier; ApprovalAction action; Approver approver; Asset asset; Outcome decision; Actor requestedFor; //... } 我有一个web服务方法: Step step = new BasicApprovalStep( n
public class Step implements IStep {
String identifier;
ApprovalAction action;
Approver approver;
Asset asset;
Outcome decision;
Actor requestedFor;
//...
}
我有一个web服务方法:
Step step = new BasicApprovalStep(
new ApprovalAction("Name Test", "Description Test", "Instructions Test"),
mockAssetService.getRandomItem(),
mockActorService.getRandomItem());
GenericEntity< Collection<Step> > entity = new GenericEntity<Collection<Step>>(Arrays.asList(new Step[]{step})) {};
System.err.println("Returning " + step + " " + step.getIdentifier() + " " + step.getRequestedFor() + " " + step.getAsset());
return Response.ok(entity).build();
我总是得到[{}]
作为对REST调用的响应。我看到打印语句,所以我知道它正在返回数据:
返回BasicApprovalStep@20d360377bde8abd-3632-47ce-98a3-d1ddafe875a1实体。Actor@19011a5d实体。Asset@442102c
为什么这不起作用,我和其他服务(审批者、参与者等)的模式相同(像这样返回结果),而且效果很好
有什么建议吗?您的API方法上有@products(“application/json”)注释吗?我有这些:`@GET@products(MediaType.application\u json)`您在类中定义了任何getter吗?为什么要返回GenericEntity,而不仅仅是一个集合?用于验证数据的日志输出正在访问
步骤
实例,但实际上返回的是实体
实例。您是否确认实体
构造正确,并且它包含您期望的内容?当我打印entity.getEntity()时,我看到:实体。BasicApprovalStep@13461dc2]
哪个是正确的
@GET
@Produces(MediaType.APPLICATION_JSON)