我有一个有几个注释的对象:
@JsonInclude(Include.NON_DEFAULT)
@JsonIgnore and
@JsonProperty("BLA BLA")`
我需要序列化我的对象,同时忽略其值未更改的字段,并且始终忽略其他一些字段。在序列化时,我希望某些字段在 json 字符串中具有不同的名称。所有这些都很好。我的问题是当我尝试动态过滤掉一些字段时!我尝试了我能找到的每一个例子,但没有任何效果,我不能动态排除字段。也许我的其他注释阻止我这样做?
这是我的代码:
@JsonInclude(Include.NON_DEFAULT)
public class objectFilter implements Serializable {
@JsonIgnore
private String filterDescription = "";
private String[] address = {"","0","false"};
@JsonProperty("status.statusCode")
private String[] statusCode = {"","0","false"};
@JsonIgnore
private String statusCodeDescription = "";
@JsonProperty("createdUser.userCode")
private String[] createdUser = {"","0","true"};
@JsonIgnore
private String createdUserDescription = "";
@JsonProperty("List.endorsment")
private String[] endorsment1 = {"","0","false"};
@JsonProperty("endorsment")
private String[] endorsment2 = {"","0","false"};
@JsonProperty("List.policy")
private String[] policy1 = {"","0","false"};
@JsonProperty("policy")
private String[] policy2 = {"","0","false"};
//getters and setters
}
我希望能够将某些字段排除在序列化之外,即使它们不使用 @JsonIgnore 例如:我想排除除 policy2 和 endorsment2 之外的所有字段,即使其他字段内部有值。
如何才能做到这一点?
请帮忙。