【发布时间】:2011-01-19 17:50:03
【问题描述】:
我正在尝试在基于 RESTEasy 的 Web 应用程序中启用 JAXB 注释支持,这篇文章是向我推荐的 (http://wiki.fasterxml.com/JacksonJAXBAnnotations)。我能够得到 jackson-xc.jar 但我看不到如何注册注释内省。目前,RESTEasy 会自动序列化我的 JSON 响应,下面适合什么?目前,RESTeasy 自动序列化 JSON 对象。
包含 jackson-xc jar,其中包含 org.codehaus.jackson.xc.JaxbAnnotationIntrospector 注册这个注解内省
ObjectMapper mapper = new ObjectMapper();
AnnotationIntrospector introspector = new JaxbAnnotationIntrospector();
// make deserializer use JAXB annotations (only)
mapper.getDeserializationConfig().setAnnotationIntrospector(introspector);
// make serializer use JAXB annotations (only)
mapper.getSerializationConfig().setAnnotationIntrospector(introspector);
【问题讨论】: