0

After moving our application war from Glassfish3 to a deployment with Payara Micro, the JAX-RS serialization (jersey + jackson) doesn't work any more.

Thanks to Adam, we solved the issue with serializing pure collections, we now encounter similar errors when returning POJOs:

@GET
@Produces("application/json")
public BirdyTO findAllDaBirdy() {
    return getBirdy();
}

where BirdyTO is a POJO which contains other POJOS and/or collections of POJOS.

That one gives us the error:

MessageBodyWriter not found for media type=application/json;charset=utf-8, type=class org.example.BirdyTO, genericType=class org.example.BirdyTO.

Strange thing is that similar interfaces in same application work fine.

Any idea?

Matthias Simon
  • 388
  • 5
  • 13
  • Have you checked that the .war contains all of the needed jackson dependencies? And could you add the BirdyTO Class code. – FrAn Feb 03 '17 at 23:21

1 Answers1

0

Mapping of POJOs to JSON is not standardized in Java EE. Glassfih 4/Payara use MOXy to map POJO to JSON by default, which uses JAXB for the mapping. See [this post by Reza Rahman] (https://blogs.oracle.com/theaquarium/entry/moxy_is_the_new_default). It is possible that BirdyTO cannot be mapped by Moxy.

If you want to use Jackson, you have to:

  • disable default Moxy feature (by setting jersey.config.server.disableMoxyJson property to true)
  • add Jackson library into your app (com.fasterxml.jackson.jaxrs)
  • turn on the JacksonFeature (provided by the Jackson library) in your JAX-RS application

More info how to do it in this answer: Customizing JSON marhsalling with GlassFish v4

Community
  • 1
  • 1
OndroMih
  • 7,280
  • 1
  • 26
  • 44
  • Gold info and correct solution. Thanks a lot! Still don't know why MOXy fails to map some POJOs, but I guess we should stick to jackson since we built our app with it in the first place. – Matthias Simon Feb 05 '17 at 15:24
  • We got it. Obviously MOXy requires the transport POJOs to have default constructors. – Matthias Simon Feb 06 '17 at 07:32
  • In Java EE 8, the mapping should be standardied by the JSON-B specification. Until then, the behavior differs in subtle differences like this. Please mark the answer as the correct anwser :) – OndroMih Feb 06 '17 at 15:56