2

I'm interested in replacing the default java serialization in EclipseLink JPA to json using the Jackson engine.
Is there a property where I can set the serialization engine for all my setup?
I know EclipseLink support serialization of json with MOXY but I have other issues with using it. I'm looking for some global settings which will free me from adding @Convert to hundreds of classes.

For example:

Class A {
  String B;
  String C;
}
@Entity
Class D {
  A a;
}

By default JPA will store field 'a' as byte array while genreating the array with java serizalization. I want to change it to text and store Class A as json.

Avner Levy
  • 6,601
  • 9
  • 53
  • 92

1 Answers1

1

It turns out this can be done quite easily with SessionEventListener which replaces all java serialization converts with your own custom Jackson based conversion.
By initializing Jackson with the following line:

    objectMapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);

You can support complex inheritance scenario and almost any java class needed (on rare exception you can add special converts).

You can find more data at: Replacing JPA java serialization engine to JSON

Avner Levy
  • 6,601
  • 9
  • 53
  • 92