jsontypedef / json-typedef-codegen

A CLI tool that generates code from JSON Typedef schemas
https://jsontypedef.com/docs/tools/jtd-codegen
MIT License
160 stars 31 forks source link

Java: support variant names different from class names, fix imports #2

Closed ucarion closed 4 years ago

ucarion commented 4 years ago

This PR includes two fixes to make Java codegen work more out of the box:

  1. All possible necessary includes are always imported, that way we don't need to rely on IDEs to do that work for us.
  2. Fix Java discriminator codegen to rely a bit less on Jackson's magic class-name-finding stuff. In particular, with this change, we go from this:
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "version")
@JsonSubTypes({
    @JsonSubTypes.Type(V1.class),
    @JsonSubTypes.Type(V2.class),
})

To this:

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "version")
@JsonSubTypes({
    @JsonSubTypes.Type(name = "v1", value = V1.class),
    @JsonSubTypes.Type(name = "v2", value = V2.class),
})