Reputation: 11309
I have looked around here and don't think this is a duplicate of any of these:
using Jackson annotations in Wildfly
jackson annotations being ignored
Wildfly and Jackson @JsonIgnore annotation
Using Wildfly 10 and deploying a war with the following class:
@Provider
public class JaxApplication implements ContextResolver<ObjectMapper> {
private final ObjectMapper mapper;
public JaxApplication() {
mapper = new ObjectMapper();
mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
//throw new RuntimeException("HERE");
}
@Override
public ObjectMapper getContext(Class<?> type) {
throw new RuntimeException("HERE");
//return mapper;
}
}
I see the exception in the constructor thrown when I deploy if it's not commented, but I don't see the one from the getContext
method when I make a request to my REST service.
I have a @JsonIgnore
annotation on an entity and it's not working, nor is the @JsonIdentityInfo
annotation I'm using
That class looks like this (imports included, to verify I'm using com.fasterxml.*)
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.List;
/**
* Created by mb995a on 7/29/2016.
*/
@Entity
@JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class, property="@request_id", scope=Request.class)
public class Request extends BaseEntity {
Do I need to do something special in my REST config?
@ApplicationPath("api")
public class RestApplication extends Application {
public RestApplication() {
super();
}
}
Any ideas?
Edited to say: I also have a unit test that uses an ObjectMapper and it serializes properly.
Upvotes: 1
Views: 1375
Reputation: 11309
For anyone else, I figured this out. The problem was that I had jackson jars in my pom that were not marked as "provided" scope. This meant that I had jars in my war file's WEB-INF/lib
directory.
Even though they are the exact same version of Wildfly's jars (I use the same version properties as the WF version I'm using) they do not work properly. Looks like the hashCode()
is different for the same annotation from different jars even if they are the exact same (checksum and everything).
So, the solution was to mark the dependencies as provided
in maven for all Jackson stuff.
Upvotes: 4