Jackson JSON:如果实现java.util.Set,则子类字段未序列化

Jackson JSON:如果实现java.util.Set,则子类字段未序列化,java,jackson,Java,Jackson,我有以下遗产 interface ResultSet extends java.util.Set<CustomResult> { public int getCount(); } @XmlAccessorType(XmlAccessType.NONE) @XmlType(name = "CustomResultSet") class CustomResultSet extends LinkedHashSet<CustomResult> implements Re

我有以下遗产

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));

}
接口结果集扩展了java.util.Set{
公共int getCount();
}
@XmlAccessorType(XmlAccessType.NONE)
@XmlType(name=“CustomResultSet”)
类CustomResultSet扩展LinkedHashSet实现ResultSet{
@xmlement(name=“count”)
私人整数计数;
公共无效集合计数(整数计数){
this.count=count
}
}
.
.
公共静态void main(){
ObjectMapper ObjectMapper=新的ObjectMapper();
objectMapper.disable(反序列化功能。在未知属性上失败);
objectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_bean);
CustomResultSet CustomResultSet=新建CustomResultSet();
CustomResult CustomResult=新CustomResult(55,“abc”);
customResultSet.setCount(11);
customResultSet.add(CustomResult);
System.out.println(objectMapper.writeValueAsString(customResultSet));
}

使用上述代码序列化集合CustomResultSet中的值,但不序列化CustomResultSet中的字段计数。

任何实现
集合
接口的操作都被Jackson视为集合,即使您在自定义类上添加注释,它也会生成JSON数组。最好的办法是为类设置一个自定义序列化程序。

1)您的代码没有编译2)您没有为
CustomResultSet
上的
count
属性设置值,那么为什么您希望为它输出JSON呢?