I've got a Session Bean with the following method:
@POST
@Consumes("application/x-www-form-urlencoded")
@Path("/calculate")
@Produces("application/json")
public CalculationResult calculate(@FormParam("childProfile") String childProfile,
@FormParam("parentProfile") String parentProfile) {
...
}
The returned CalculationResult cannot be mapped to JSON and the following exception occurs:
Caused by: com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class com.test.UniqueName and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS)...
How can I configure Jackson and its SerializationFeature
in Wildfly?
Wildfly 9
pom.xml
Java class
You don't need to configure it in Wildfly, you can configure it in the JAX-RS applciation. Just use a
ContextResolver
to configure theObjectMapper
(see more here). Something likeIf you don't already have the Jackson dependency, you need that, just as a compile-time dependency
If you are using scanning to discover your resource classes and provider classes, the
ContextResolver
should be discovered automatically. If you explicitly registering all your resource and providers, then you'll need to register this one also. It should be registered as a singleton.UPDATE
As @KozProv mentions in a comment, it should actually be
resteasy-jackson2-provider
as the artifactId for the Maven dependency.-jackson-
uses the olderorg.codehaus
(Jackson 1.x), while the-jackson2-
uses the newcom.fasterxml
(Jackson 2.x). Wildfly by default uses The Jackson 2 version.