You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
prop1 works as expected (but is limited to non-primitive).
prop2 works partly. The generated pojo is as expected, but a "long.java" class is also generated that I have to manually delete. This is because jsonschema2pojo uses ClassLoader.loadClass to check for existing classes, but this method doesn't work for primitives. A common way to handle primitive class lookup is to just make your own Map<String,Class> lookup. See http://stackoverflow.com/questions/180097/dynamically-find-the-class-that-represents-a-primitive-java-type
prop3 and prop4 don't work (the pojo has int/Integer) because javaType is only used for type:object. But I wish they would work because my field is really a (64-bit) integer, not an object.
From [email protected] on February 24, 2012 22:03:35
Christopher, thanks for taking the time to raise this.
I think you're definitely right to identify a gap here. Integers as described by JSON Schema aren't limited to 32-bits (like Java ints), but for most people int is an efficient and aesthetically pleasing type to use. I think we should support those who need wider integer types though.
I'll definitely add support for primitives via javaType (probably using the Map<String,Class> approach as you suggest). For the occasional wide integer, "javaType":"long" would be very useful. I can see that some people might find this tedious if it has to be repeated for all their properties though so I think adding a new configurable property would also be a good idea.
Something along the lines of:
useLongIntegers (default false)
Which will cause all "type":"integer" properties to have a the Java primitive type "long" or "Long" (depending on the usePrimitives property value).
javaType now supports primitives (rcd225332b328), and there is also a new config option 'useLongIntegers' to universally switch all Integers to Longs in generated POJOs (r0685bcf9474a).
Original author: [email protected] (February 24, 2012 20:57:23)
I want to generate some pojos with 64bit integer (i.e. long) fields. I can't use type=number (java type Double) because of the loss of precision.
Refer to this json schema:
{
"type":"object",
"properties":{
"prop1":{"type":"object", "javaType":"java.lang.Long"},
"prop2":{"type":"object", "javaType":"long"},
"prop3":{"type":"integer", "javaType":"java.lang.Long"},
"prop4":{"type":"integer", "javaType":"long"}
}
}
prop1 works as expected (but is limited to non-primitive).
prop2 works partly. The generated pojo is as expected, but a "long.java" class is also generated that I have to manually delete. This is because jsonschema2pojo uses ClassLoader.loadClass to check for existing classes, but this method doesn't work for primitives. A common way to handle primitive class lookup is to just make your own Map<String,Class> lookup. See http://stackoverflow.com/questions/180097/dynamically-find-the-class-that-represents-a-primitive-java-type
prop3 and prop4 don't work (the pojo has int/Integer) because javaType is only used for type:object. But I wish they would work because my field is really a (64-bit) integer, not an object.
Original issue: http://code.google.com/p/jsonschema2pojo/issues/detail?id=41
The text was updated successfully, but these errors were encountered: