Search code examples
javagenson

Only add class metadata for non-concrete types in Genson


So I can do the following new GensonBuilder().useClassMetadata(true) and Genson will add a @Class element to the Json Object with the class name when it serializes.

Is there any way I can have this happen only when it comes to a runtime type that is different to compile time.

E.g.

class MyType {

    public MyType myType;
    public Objct myType2;
}

I would expect a @Class element on myType2 when serialized, but not myType.


Solution

  • No, at the moment there is no such option. You could easily implement your use case by modifying ClassMetadataConverter. If you do it, it might be great to make a PR with your changes.

    Update In latest Genson release 1.1, you have now an option in the builder to enable this behaviour:

    new GensonBuilder().useClassMetadataWithStaticType(false).create();