Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jboss 7.1.1 - Jackson ContextResolver<ObjectMapper> works only on one deployment

I have two rest webapps I want to deploy on Jboss 7.1.1. server.

Rest requests in both apps produces and consumes Json. I use jackson provider to serialize and deserialize objects.

Now, I need custom ObjectMapper configurations for each webapp. So to resolve this problem I added @Provider classes implementing ContextResolver. One for each project. Fe. One of my class looks like that:

@provider
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class JacksonConfig implements ContextResolver<ObjectMapper> {
   private final ObjectMapper objectMapper;
   public JacksonConfig()
   {
       objectMapper = new ObjectMapper();
       objectMapper.configure(SerializationConfig.Feature.WRAP_ROOT_VALUE, true);
   }
   @Override
   public ObjectMapper getContext(Class<?> objectType) {
       return objectMapper;
   }
}

It works well when I deploy only one of this projects on jboss. When I try to deploy both, only first initialized project use defined objectMapper. Other one never calls getContext method from ContextResolver class. What could I do wrong?

EDIT!:

After a lot of trials I decided to change method of parsing json from jackson to staxon. I hoped at least this method will work well. But not... Serialization works perfectly on both deployed applications. But again, somehow jboss decided to use jackson instead of staxon in deserialization process. Again always application which I call first after deployment works well. But Second one using jackson (no idea why...) which calls exceptions. Always...

Is there any problem with Jboss? Probably I'm just doing something wrong but I have no idea where. Anybody has idea where should I look?

like image 394
rychu Avatar asked Feb 06 '13 14:02

rychu


1 Answers

Looks like I found solution for this problem. It was known issue of resteasy, that can be removed by build-in option:

To solve this problem I just had to add param to web.xml of my projects:

<context-param>
    <param-name>resteasy.use.deployment.sensitive.factory</param-name>
    <param-value>false</param-value>
</context-param>

I found this solution in Resteasy jira. It's really strange for me that there is no info in any jboss or resteasy related documentation...

like image 173
rychu Avatar answered Sep 21 '22 23:09

rychu