Chu*_*k M 8 java web-services jaxb resteasy jackson
我正在将Ant RestEasy项目转换为Maven.我有大部分时间再次运行,有一个问题.JSON输出不像以前那样工作.例如,这是一个获得输出的简单实体:
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "site-recode")
public class SiteRecode {
@XmlElement(name = "site", required = true)
protected String _site;
@XmlElement(name = "hist", required = true)
protected String _hist;
@XmlElement(name = "ks_and_meso", required = true)
protected Boolean _withKsAndMeso;
@XmlElement(name = "site-group", required = true)
protected String _siteGroup;
public SiteRecode() {
}
public SiteRecode(String site, String hist, Boolean withKsAndMeso, String siteGroup) {
this._site = site;
this._hist = hist;
this._withKsAndMeso = withKsAndMeso == null ? Boolean.TRUE : withKsAndMeso;
this._siteGroup = siteGroup;
}
}
Run Code Online (Sandbox Code Playgroud)
这是我用于RestEasy的上下文解析器:
@Provider
@Produces(MediaType.APPLICATION_JSON)
public class JacksonContextResolver implements ContextResolver<ObjectMapper> {
private ObjectMapper _objectMapper;
public JacksonContextResolver() {
_objectMapper = new ObjectMapper();
_objectMapper.setAnnotationIntrospector(new JaxbAnnotationIntrospector());
}
public ObjectMapper getContext(Class<?> objectType) {
return _objectMapper;
}
}
Run Code Online (Sandbox Code Playgroud)
在我们的旧Ant构建下,JSON和XML输出都很有效.XML输出仍然完美.现在,如果我尝试获取JSON,我会收到此异常:
引起:org.codehaus.jackson.map.JsonMappingException:找不到类com.imsweb.seerapi.siterecode.SiteRecode的序列化器,并且没有发现创建BeanSerializer的属性(为了避免异常,请禁用SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS))
我发现了两件事.
{
"_hist": "9650",
"_site": "C379",
"_siteGroup": "33011",
"_withKsAndMeso": true
}
{
"hist": "9650",
"site": "C379",
"siteGroup": "33011",
"withKsAndMeso": true
}
所以基本上它完全忽略了我的注释.如果它们是公共的,它将显示默认的命名字段/方法.
但是,XML输出仍然可以完美地工作并且遵循注释名称:
<site-recode>
<site>C379</site>
<hist>9650</hist>
<ks_and_meso>true</ks_and_meso>
<site-group>33011</site-group>
</site-recode>
Run Code Online (Sandbox Code Playgroud)
我看过Ant和Maven生成的WAR文件,我无法弄清楚我在做什么不同.有没有人见过这样的东西?谢谢.
更新:
我想到了.我忘了在pom.xml中正确设置清单.我只需要添加:
<manifestEntries>
<Dependencies>org.codehaus.jackson.jackson-xc,org.codehaus.jackson.jackson-mapper-asl,org.codehaus.jackson.jackson-core-asl,org.apache.commons.logging export,org.apache.log4j export</Dependencies>
</manifestEntries>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3046 次 |
最近记录: |