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
What is the expected output?
Code generated successfully.
What do you see instead?
java.lang.NumberFormatException (stack trace pasted below)
What version of the product are you using?
0.3.0
On what Java version?
java version "1.6.0_30"
Adding this code to the beginning of method resolves the issue (DefaultRule.getDefaultValue(DefaultRule.java:92))
private JExpression getDefaultValue(JType fieldType, JsonNode node) {
if( node.isNull() ){
return JExpr._null();
}
Stack Trace:
Exception in thread "main" java.lang.NumberFormatException: For input string: "null"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at com.googlecode.jsonschema2pojo.rules.DefaultRule.getDefaultValue(DefaultRule.java:101)
at com.googlecode.jsonschema2pojo.rules.DefaultRule.apply(DefaultRule.java:84)
at com.googlecode.jsonschema2pojo.rules.DefaultRule.apply(DefaultRule.java:1)
at com.googlecode.jsonschema2pojo.rules.PropertyRule.apply(PropertyRule.java:108)
at com.googlecode.jsonschema2pojo.rules.PropertyRule.apply(PropertyRule.java:1)
at com.googlecode.jsonschema2pojo.rules.PropertiesRule.apply(PropertiesRule.java:62)
at com.googlecode.jsonschema2pojo.rules.PropertiesRule.apply(PropertiesRule.java:1)
at com.googlecode.jsonschema2pojo.rules.ObjectRule.apply(ObjectRule.java:108)
at com.googlecode.jsonschema2pojo.rules.ObjectRule.apply(ObjectRule.java:1)
at com.googlecode.jsonschema2pojo.rules.TypeRule.apply(TypeRule.java:95)
at com.googlecode.jsonschema2pojo.rules.TypeRule.apply(TypeRule.java:1)
at com.googlecode.jsonschema2pojo.rules.JsonSchemaRule.apply(JsonSchemaRule.java:73)
at com.googlecode.jsonschema2pojo.rules.JsonSchemaRule.apply(JsonSchemaRule.java:66)
at com.googlecode.jsonschema2pojo.rules.JsonSchemaRule.apply(JsonSchemaRule.java:1)
at com.googlecode.jsonschema2pojo.SchemaMapperImpl.generate(SchemaMapperImpl.java:65)
at com.googlecode.jsonschema2pojo.cli.Jsonschema2Pojo.generate(Jsonschema2Pojo.java:92)
at com.googlecode.jsonschema2pojo.cli.Jsonschema2Pojo.main(Jsonschema2Pojo.java:60)
From [email protected] on July 09, 2012 20:20:52
We need to tread a bit carefully here as it's possible that people are using primitive types (e.g. usePrimitives=true) and we don't want to generate code that fails to compile. It will probably be simpler to leave the value uninitialized when "default":null is present (as this will work for all objects including wrapper types, but will leave primitive types with their natural default).
I'm interested to know, why would you write a schema like this? Is this simply a contrived example to reproduce the bug?
It's a contrived example to reproduce the bug. I'm consuming someone
else's REST service and their schema has number fields that are initialized
to null.
Could this work?
private JExpression getDefaultValue(JType fieldType, JsonNode node) {
if( !fieldType.isPrimitive() && node.isNull() ){
return JExpr._null();
}
Original author: [email protected] (July 09, 2012 19:25:43)
What steps will reproduce the problem?
{
"id": "test",
"type": "object",
"additionalProperties": false,
"properties": {
"age": {
"type": "integer",
"default": null,
"minimum": 0
}
}
}
What is the expected output?
Code generated successfully.
What do you see instead?
java.lang.NumberFormatException (stack trace pasted below)
What version of the product are you using?
0.3.0
On what Java version?
java version "1.6.0_30"
Adding this code to the beginning of method resolves the issue (DefaultRule.getDefaultValue(DefaultRule.java:92))
private JExpression getDefaultValue(JType fieldType, JsonNode node) {
if( node.isNull() ){
return JExpr._null();
}
Stack Trace:
Exception in thread "main" java.lang.NumberFormatException: For input string: "null"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at com.googlecode.jsonschema2pojo.rules.DefaultRule.getDefaultValue(DefaultRule.java:101)
at com.googlecode.jsonschema2pojo.rules.DefaultRule.apply(DefaultRule.java:84)
at com.googlecode.jsonschema2pojo.rules.DefaultRule.apply(DefaultRule.java:1)
at com.googlecode.jsonschema2pojo.rules.PropertyRule.apply(PropertyRule.java:108)
at com.googlecode.jsonschema2pojo.rules.PropertyRule.apply(PropertyRule.java:1)
at com.googlecode.jsonschema2pojo.rules.PropertiesRule.apply(PropertiesRule.java:62)
at com.googlecode.jsonschema2pojo.rules.PropertiesRule.apply(PropertiesRule.java:1)
at com.googlecode.jsonschema2pojo.rules.ObjectRule.apply(ObjectRule.java:108)
at com.googlecode.jsonschema2pojo.rules.ObjectRule.apply(ObjectRule.java:1)
at com.googlecode.jsonschema2pojo.rules.TypeRule.apply(TypeRule.java:95)
at com.googlecode.jsonschema2pojo.rules.TypeRule.apply(TypeRule.java:1)
at com.googlecode.jsonschema2pojo.rules.JsonSchemaRule.apply(JsonSchemaRule.java:73)
at com.googlecode.jsonschema2pojo.rules.JsonSchemaRule.apply(JsonSchemaRule.java:66)
at com.googlecode.jsonschema2pojo.rules.JsonSchemaRule.apply(JsonSchemaRule.java:1)
at com.googlecode.jsonschema2pojo.SchemaMapperImpl.generate(SchemaMapperImpl.java:65)
at com.googlecode.jsonschema2pojo.cli.Jsonschema2Pojo.generate(Jsonschema2Pojo.java:92)
at com.googlecode.jsonschema2pojo.cli.Jsonschema2Pojo.main(Jsonschema2Pojo.java:60)
Original issue: http://code.google.com/p/jsonschema2pojo/issues/detail?id=61
The text was updated successfully, but these errors were encountered: