jsonschema2pojo
jsonschema2pojo copied to clipboard
Generated attribute takes first type on types list.
Consider the following jsonSchema:
{
"type" : "object",
"properties" : {
"foo" : {
"type" : ["boolean", "string","number","integer"]
}
}
}
In this case generated attribute foo will have as type Boolean:
package com.example;
import javax.annotation.Generated;
@Generated("jsonschema2pojo")
public class Example {
public Boolean foo;
}
I noticed that, if type is not specified in jsonSchema, foo takes the type Object:
{
"type" : "object",
"properties" : {
"foo" : {
}
}
}
Result:
package com.example;
import javax.annotation.Generated;
@Generated("jsonschema2pojo")
public class Example {
public Object foo;
}
There's a way of having the last result (without changing the jsonSchema) when a list of types is passed ?
Maybe related to #676 ?
Yes, it's directly related and the answer will be the same
Often people use union types like: ["boolean", null], where the result is an optional value. In this case, it's obviously desirable to just take the first item. It would probably be better if use we use the following logic for union types:
- Remove
nullvalues. - If one value remains, use this as the type; If multiple values remain, use Object as the type.
Logic of taking first type should be changed, as a user can pass ["null", "boolean"] and should have the same result