birnbaum birnbaum - 5 months ago 45x
Java Question

How is serializing objects to json?

What serializer is

using to serialize/deserialize objects? Is it somehow possible to use a custom serializer?

In my case the serialization is wrong because my object contains fields with the Guava Optional data type and absent values are returned as
instead of


The JSON serializer isn't specified by JAX-RS, it depends on your configuration. For example, Jersey JAX-RS allows several (, including

  • MOXy
  • Java API for JSON Processing (JSON-P)
  • Jackson
  • Jettison

But a better solution is not to use Optional (either Guava or Java 8) for fields. See

My only fear is that Optional will be overused. Please focus on using it as a return type (from methods that perform some useful piece of functionality) Please don't use it as the field of a Java-Bean.