简体   繁体   English

Wildfly 8.2 Resteasy无需编组XMLRootElement

[英]Wildfly 8.2 Resteasy not Marshalling XMLRootElement

I am updating a very simple Rest service to Wildfly 8.2 from jBoss 7.2 and have hit a problem where the objects returned from the service methods that Resteasy converts to json are not including the XMLRootElement defined on the objects. 我正在将一个非常简单的Rest服务从jBoss 7.2更新到Wildfly 8.2,并遇到了一个问题,即从Resteasy转换为json的服务方法返回的对象不包括在对象上定义的XMLRootElement。

I'm using maven and set all java libraries to 'provided' so using the versions bundled in Wildfly. 我正在使用maven并将所有Java库都设置为“提供”,因此请使用Wildfly中捆绑的版本。

My current jboss-deployment-structure.xml does not include or exclude anything but i've tried switching between jettison and jaxb but always hit the same problem. 我当前的jboss-deployment-structure.xml不包含或排除任何内容,但我尝试在jettison和jaxb之间切换,但始终遇到相同的问题。

Has anyone seen this and found a solution or am I missing something simple? 有没有人看到这并找到解决方案,还是我错过了一些简单的东西?

Thanks for advice in advance. 预先感谢您的建议。

After several hours of digging and trying things out, (before posting this question) I found that adding the following class to configure the mapper sorted the issue. 经过几个小时的挖掘和尝试,(在发布此问题之前),我发现添加以下类来配置映射器可以解决该问题。 It seems that by default, Resteasy no longer wraps the root element so you have to configure it to do so.... 似乎默认情况下,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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM