0

How can I force the jsonschema2pojo generated class to implement serializable interface? I am parsing plain json and not JSON Schema so making the json contain "javaInterfaces" array is out of the question. Here is the working code:

    JCodeModel codeModel = new JCodeModel();
    SchemaMapper mapper = new SchemaMapper(new RuleFactory(config, new GsonAnnotator(), new SchemaStore()), new SchemaGenerator());
    mapper.generate(codeModel, className, packageName, jsonStr);
    return codeModel;
Oleksiy Martynov
  • 379
  • 2
  • 11

2 Answers2

1

This is possible in 0.4.23 (and later) of jsonschema2pojo. Just set the 'serializable' property to true:

GenerationConfig config = new DefaultGenerationConfig() {
...
@Override
public boolean isSerializable() {
    return true;
}
...
} 
joelittlejohn
  • 11,665
  • 2
  • 41
  • 54
0

To answer my own question: I could not find a way to implement Serializable but I can implement Parcelable which works for me.

GenerationConfig config = new DefaultGenerationConfig() {
...
@Override
public boolean isParcelable() {
    return true;
}
...
}
Oleksiy Martynov
  • 379
  • 2
  • 11