![](/img/trans.png)
[英]enabling auto scanning using resteasy 3.0.10 with wildfly 8.2
[英]Wildfly 8.2 Resteasy not Marshalling XMLRootElement
我正在將一個非常簡單的Rest服務從jBoss 7.2更新到Wildfly 8.2,並遇到了一個問題,即從Resteasy轉換為json的服務方法返回的對象不包括在對象上定義的XMLRootElement。
我正在使用maven並將所有Java庫都設置為“提供”,因此請使用Wildfly中捆綁的版本。
我當前的jboss-deployment-structure.xml不包含或排除任何內容,但我嘗試在jettison和jaxb之間切換,但始終遇到相同的問題。
有沒有人看到這並找到解決方案,還是我錯過了一些簡單的東西?
預先感謝您的建議。
經過幾個小時的挖掘和嘗試,(在發布此問題之前),我發現添加以下類來配置映射器可以解決該問題。 似乎默認情況下,Resteasy不再包裝根元素,因此您必須對其進行配置。
@Provider
public class ObjectMapperContextResolver implements ContextResolver<ObjectMapper>
{
private final ObjectMapper mapper;
public ObjectMapperContextResolver()
{
mapper = new ObjectMapper();
mapper.configure(SerializationConfig.Feature.WRAP_ROOT_VALUE, true);
}
@Override
public ObjectMapper getContext(Class<?> type)
{
return mapper;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.