我的目的是仅使用非空对象打印Json。如附图所示,我有空物体,我不想打印它们。选择Gson还是Jackson都没关系,等等。
到目前为止,尝试了很多组合,但都没有用
我的数据结构是:
Map<AWSRegion, List<SecurityGroupDiff>> listEntry...
public class SecurityGroupDiff {
@JsonInclude(Include.NON_EMPTY) ... // on all fields/objects
private String groupId;
private String groupName;
private String vpcId;
private String owner;
private String type;
private List<IPPermissionDiff> ipPermissionDiffs;
}
到目前为止的Tryid:
private static final ObjectMapper MAPPER = new ObjectMapper().
setSerializationInclusion(Include.NON_NULL).setSerializationInclusion(Include.NON_EMPTY).setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
MAPPER.writerWithDefaultPrettyPrinter()
.writeValueAsString(listEntry)
结果仍然相同...
{
"CANADA" : [ { }, { }, { }, { }, {
"ipPermissionDiffs" : [ { }, { }, { }, { } ]
}, { }, { }, { } ],
"ASIA_SIDNEY" : [ {
"ipPermissionDiffs" : [ { }, { }, { }, { }, { } ]
}, { }, { }, { }, { }, { }, { }, {
"ipPermissionDiffs" : [ { }, { }, { }, { } ]
}, { } ],
"EU" : [ { }, { }, { }, { }, { }, { }, { }, { }, {
"ipPermissionDiffs" : [ { }, { }, { }, { }, { }, { }, { } ]
}, { } ]
}
谢谢