reinert / JJSchema

A generator from Java Types to JSON-Schema using Jackson.
Other
117 stars 56 forks source link

Support of @JsonProperty #89

Closed WhileTrueEndWhile closed 6 years ago

WhileTrueEndWhile commented 6 years ago

Hi,

JJSchema ignores the @JsonProperty annotation, which causes Jackson to create a JSON object which differs from the JSON schema definition.

Let's take a look at the following example class...

public class MyClass {
    @JsonProperty("my_attribute")
    private String myAttribute;

    public String getMyAttributes() { return myAttribute; }
    public MyClass setMyAttribute(String myAttribute) { this.myAttribute = myAttribute; return this; }
}

The code ...

new ObjectMapper().writeValueAsString(new MyClass().setMyAttribute("Hello World"));

... produces ...

{
    "my_attribute": "Hello World"
}

... but JJSchema produces ...

{
    "properties": {
        "myAttribute": { "type": "string" }
    }
}

Any ideas?


I found a dirty solution which is documented in the current test:

https://github.com/WhileTrueEndWhile/JJSchema/blob/master/src/test/java/com/github/reinert/jjschema/xproperties/XPropertiesTest.java

Using an X Property like properties = com.github.reinert.jjschema.xproperties.XPropertiesTest$RenameFactory:example -> another_name renames example to another_name...