我的应用程序中,JAXB输出的格式如下:
this.marshalOut(jaxb_Object, fileOutputStream);
这是调用Spring对象XML映射马歇尔生成XML文件的方法。现在,我也想在此行之后生成JSON文件。有人知道如何使用JAXB输入生成JSON输出吗?
我在网上找到了这个示例代码:
ObjectMapper mapper = new ObjectMapper();
AnnotationIntrospector introspector = new JacksonAnnotationIntrospector();
// make deserializer use JAXB annotations (only)
mapper.getDeserializationConfig().setAnnotationIntrospector(introspector);
// make serializer use JAXB annotations (only)
mapper.getSerializationConfig().setAnnotationIntrospector(introspector);
mapper.writeValue( outputStream, jaxb_object);
setAnnotationIntrospector
已经被弃用,是否有其他解决方法?