Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Json JaxB注释和Jackson空列表响应_Json_Jaxb_Annotations_Jackson_Xmladapter - Fatal编程技术网

Json JaxB注释和Jackson空列表响应

Json JaxB注释和Jackson空列表响应,json,jaxb,annotations,jackson,xmladapter,Json,Jaxb,Annotations,Jackson,Xmladapter,有人有JaxB Annotation@XmlJavaTypeAdapter与Jackson合作的例子吗?尝试序列化列表对象时,我无法使其工作 我的场景如下所示。我必须使用XML注释,因为bean是自动生成的,并且不同的模块基于bean生成XML/JSON数据——这就是我所拥有的示例- 接口A,抽象类B实现了A,很多bean都是从B派生的 @XmlJavaTypeAdapter(A.class,AAdapter.class) C类{ String type; List<B> list

有人有JaxB Annotation@XmlJavaTypeAdapter与Jackson合作的例子吗?尝试序列化列表对象时,我无法使其工作

我的场景如下所示。我必须使用XML注释,因为bean是自动生成的,并且不同的模块基于bean生成XML/JSON数据——这就是我所拥有的示例-

接口A,抽象类B实现了A,很多bean都是从B派生的

@XmlJavaTypeAdapter(A.class,AAdapter.class)

C类{

String type;

List<B> listOfBeans;
}

尝试序列化C的对象时,列表输出始终为空,尽管它具有所有有效的对象。看起来无法找到列表对象B的序列化程序(它调用unknownSerializer)

{ “listOfBeans”:[{},{}], “类型”:“holderForListOfBeans” }

我的对象映射器是-

private ObjectMapper initializeJackson() {
    ObjectMapper mapper = new ObjectMapper();
    mapper.setDateFormat(new SimpleDateFormat(TWS_DATE_FORMAT));
    mapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);
    mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
    mapper.setSerializationInclusion(Include.NON_NULL);

    // Need to use JaxB Annotation.
    JaxbAnnotationModule module = new JaxbAnnotationModule();
    mapper.registerModule(module);

    // All 64 bit fields should be quoted. Use StringSerializer for them.
    SimpleModule mySimpleModule = new SimpleModule();
    mySimpleModule.addSerializer(Long.class, new ToStringSerializer());
    mySimpleModule.addSerializer(Double.class, new ToStringSerializer());
    mapper.registerModule(mySimpleModule);

    return mapper;
}
private ObjectMapper initializeJackson() {
    ObjectMapper mapper = new ObjectMapper();
    mapper.setDateFormat(new SimpleDateFormat(TWS_DATE_FORMAT));
    mapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);
    mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
    mapper.setSerializationInclusion(Include.NON_NULL);

    // Need to use JaxB Annotation.
    JaxbAnnotationModule module = new JaxbAnnotationModule();
    mapper.registerModule(module);

    // All 64 bit fields should be quoted. Use StringSerializer for them.
    SimpleModule mySimpleModule = new SimpleModule();
    mySimpleModule.addSerializer(Long.class, new ToStringSerializer());
    mySimpleModule.addSerializer(Double.class, new ToStringSerializer());
    mapper.registerModule(mySimpleModule);

    return mapper;
}