Converter responsible of writing and reading @class metadata. This is useful if you want to be
able to deserialize all serialized objects without knowing their concrete type. Metadata is
written only in objects (never in arrays or literals) and is always the first element in the
object. Most default converters are annotated with @HandleClassMetada indicating that they will
not have class metadata written nor use it during deserialization. This feature is disabled by
default, to enable it use
Builder.setWithClassMetadata(true). Genson provides also a aliases mechanism that will replace
the class name with the value of your alias in the generated stream. You should use it as it is
more "secure" and provides you more flexibility. Indeed if you change the name or package of your
class you will still be able to deserialize to it. An example allowing to serialize a object and then deserialize it back
without knowing its type would be:
class Foo {
}
Genson genson = new Genson.Builder().setWithClassMetadata(true).addAlias("foo", Foo.class).create();
String json = genson.serialize(new Foo());
// json value will be {"@class":"Foo"}
Foo foo = (Foo) genson.deserialize(json, Object.class);