我有以下继承
interface ResultSet extends java.util.Set<CustomResult> {
public int getCount();
}
@XmlAccessorType(XmlAccessType.NONE)
@XmlType(name = "CustomResultSet")
class CustomResultSet extends LinkedHashSet<CustomResult> implements ResultSet {
@XmlElement(name = "count")
private int count;
public void setCount(int count) {
this.count = count
}
}
.
.
public static void main() {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
objectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
CustomResultSet customResultSet = new CustomResultSet();
CustomResult customResult = new CustomResult(55, "abc");
customResultSet.setCount(11);
customResultSet.add(CustomResult);
System.out.println(objectMapper.writeValueAsString(customResultSet));
}
使用上面的代码序列化集合 CustomResultSet 中的值,但不序列化 CustomResultSet 中的字段计数。