3 ms·
> Automated serialization is the devil. Gson and Jackson require you to write EJB-style objects to get automatic serialization - default constructors, with gett
by vonmoltke 10y ago
> Automated serialization is the devil. Gson and Jackson require you to write EJB-style objects to get automatic serialization - default constructors, with getters and setters for each field - to achieve automatic serialization.
Gson does not require this. The following class will serialize and deserialze fine with Gson:
class Example {
private final int foo;
private final String bar;
private Example(final int foo, final String bar) {
this.foo = foo;
this.bar = bar;
}
}
More complicated cases will require custom serializers and deserializers, but any class that defines only basic data types (including collections) works just fine.