-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
When trying to run jsonschema2pojo on a json schema that has an enum property with a name starting with a capital letter, the generated code doesn't compile.
The compilation error is: non-static variable 'x' cannot be referenced from a static context.
That error occurs because the generated code has a private field with the same name as the enum, that is later accessed by that name from a static code block.
According to RFC 4627 - there is no requirement for member names to start with lower case letters.
For example, for the JSON schema:
{
"type": "object",
"properties": {
"ExampleObj": {
"type": "object",
"properties": {
"TimeFormat": {
"enum": [ "12h", "24h" ],
"description": "The referred time display format, either 12 or 24 hour clock."
}
}
}
}
}
That error occurs because the generated code has a private field with the name TimeFormat:
@JsonProperty("TimeFormat")
private ExampleObj.TimeFormat TimeFormat;
and an enum with the same name, that tries to access that field from within a static code block (note the ExampleObj.TimeFormat.values() within the foreach loop):
@Generated("com.googlecode.jsonschema2pojo")
public static enum TimeFormat {
_12_H("12h"),
_24_H("24h");
private final String value;
private static Map constants = new HashMap();
static {
for (ExampleObj.TimeFormat c: ExampleObj.TimeFormat.values()) {
constants.put(c.value, c);
}
}
.
.
.