0

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.

Cheetah
  • 13,785
  • 31
  • 106
  • 190

1 Answers1

0

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();
eugen
  • 5,856
  • 2
  • 29
  • 26
  • I did have a quick look into this but it didn't look like I'd have what was required to achieve this. Thanks for the answer. – Cheetah Jul 21 '14 at 18:39
  • Ok, I have created an issue for your use case https://github.com/owlike/genson/issues/17, see if the description helps you to implement it. Don't hesitate to ask there for help to implement it. – eugen Jul 21 '14 at 19:25
  • Ah didn't see that `tClass` was available...will have a hack around soon - thanks. – Cheetah Jul 22 '14 at 09:09
  • I am getting a `"val$scanner":{}` on everything I serialize, I get the same in version 1.1 too. – Cheetah Sep 22 '14 at 19:27
  • Can you please post an example on genson mailing list? – eugen Sep 23 '14 at 12:11