Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression: when a extending a schema with a redefinition of the same field, with methods should be generated only once #507

Closed
peterhendriks opened this issue Feb 18, 2016 · 3 comments
Milestone

Comments

@peterhendriks
Copy link

When upgrading from version 0.4.16 to a higher release we've encountered the following issue: when redefining the same field as in a extended schema, the corresponding "with" method is generated twice: once with a @OverRide, and once without. This means the generated code does not compile. Not that the get and set are generated once, but without an @overrride, although these methods also override base methods.

In 0.4.16, only the "with" method without the Override annotation is generated. We currently use this to restrict and default certain fields in subtypes, this blocks us from upgrading to a higher release.

Full example given the following two schema's:

{
  "$schema": "http://json-schema.org/draft-03/schema#",
  "type": "object",
  "javaType": "BaseEvent",
  "properties": {
    "eventType": {
      "type": "string",
      "required": true
    }
  },
  "additionalProperties": false
}

{
  "$schema": "http://json-schema.org/draft-03/schema#",
  "type": "object",
  "javaType": "SpecificEvent",
  "extends": {
    "$ref": "BaseEvent.schema.json"
  },
  "properties": {
    "eventType": {
      "type": "string",
      "required": true,
      "pattern": "^search$",
      "default": "search"
    }
  },
  "additionalProperties": false
}

The following erroneous code gets generated:

public class SpecificEvent  extends BaseEvent
{
    @NotNull
    @JsonProperty("eventType")
    @Pattern(regexp = "^search$")
    private String eventType = "search";

    @JsonProperty("eventType")
    public String getEventType() {
        return eventType;
    }

    @JsonProperty("eventType")
    public void setEventType(String eventType) {
        this.eventType = eventType;
    }

    public SpecificEvent withEventType(String eventType) {
        this.eventType = eventType;
        return this;
    }

    @Override
    public SpecificEvent withEventType(String eventType) {
        super.withEventType(eventType);
        return this;
    }
}
@joelittlejohn
Copy link
Owner

Thanks for reporting this. I suspect this was caused by the changes related to #455.

@joelittlejohn joelittlejohn added this to the 0.4.20 milestone Feb 21, 2016
@peterhendriks
Copy link
Author

Thanks for the quick fix!

@joelittlejohn
Copy link
Owner

No problem. Check out 0.4.20 that is available in central now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants