简体   繁体   中英

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.

I'm using maven and set all java libraries to 'provided' so using the versions bundled in 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.

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....

    @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;
        }

    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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