Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give more detail when a JSON schema triggers parse exception #51

Closed
joelittlejohn opened this issue Jun 23, 2013 · 1 comment
Closed

Comments

@joelittlejohn
Copy link
Owner

Original author: PaulGr...@gmail.com (May 30, 2012 20:10:12)

What steps will reproduce the problem?

  1. Use an invalid schema. This one is missing a comma after ("id": "Market"):

{
"description": "An object describing a betting market for a match",
"type": "object",
"id": "Market"
"properties": {
"name": {
"type": "string"
},
"handicap": {
"type": "string"
},
"odds": {
"type": "string"
},
"bookmaker": {
"type": "string"
}
}
}

  1. Try and generate.
  2. Get com.fasterxml.jackson.core.JsonParseException.

What is the expected output?

An exception is thrown, but it doesn't tell you which of your schema files is at fault:

Preparing to Execute Maven in Debug Mode
Listening for transport dt_socket at address: 8000
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Unnamed - xxx.xxx:xxx:war:0.0.1-SNAPSHOT
[INFO] task-segment: [compile]
[INFO] ------------------------------------------------------------------------
[INFO] [jsonschema2pojo:generate {execution: default}]
[INFO] ------------------------------------------------------------------------
[ERROR] FATAL ERROR
[INFO] ------------------------------------------------------------------------
[INFO] com.fasterxml.jackson.core.JsonParseException: Unexpected character ('"' (code 34)): was expecting comma to separate OBJECT entries
at [Source: java.io.BufferedInputStream@ed8eb5; line: 5, column: 6]
[INFO] ------------------------------------------------------------------------
[INFO] Trace
com.googlecode.jsonschema2pojo.exception.GenerationException: com.fasterxml.jackson.core.JsonParseException: Unexpected character ('"' (code 34)): was expecting comma to separate OBJECT entries
at [Source: java.io.BufferedInputStream@ed8eb5; line: 5, column: 6]
at com.googlecode.jsonschema2pojo.Schema.create(Schema.java:73)
at com.googlecode.jsonschema2pojo.Schema.create(Schema.java:104)
at com.googlecode.jsonschema2pojo.rules.JsonSchemaRule.apply(JsonSchemaRule.java:59)
at com.googlecode.jsonschema2pojo.rules.JsonSchemaRule.apply(JsonSchemaRule.java:30)
at com.googlecode.jsonschema2pojo.SchemaMapperImpl.generate(SchemaMapperImpl.java:65)
at com.googlecode.jsonschema2pojo.cli.Jsonschema2Pojo.generate(Jsonschema2Pojo.java:88)
at com.googlecode.jsonschema2pojo.maven.Jsonschema2PojoMojo.execute(Jsonschema2PojoMojo.java:172)
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:556)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:535)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: com.fasterxml.jackson.core.JsonParseException: Unexpected character ('"' (code 34)): was expecting comma to separate OBJECT entries
at [Source: java.io.BufferedInputStream@ed8eb5; line: 5, column: 6]
at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1274)
at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:588)
at com.fasterxml.jackson.core.base.ParserMinimalBase._reportUnexpectedChar(ParserMinimalBase.java:509)
at com.fasterxml.jackson.core.json.UTF8StreamJsonParser.nextToken(UTF8StreamJsonParser.java:488)
at com.fasterxml.jackson.databind.deser.std.BaseNodeDeserializer.deserializeObject(JsonNodeDeserializer.java:192)
at com.fasterxml.jackson.databind.deser.std.JsonNodeDeserializer.deserialize(JsonNodeDeserializer.java:58)
at com.fasterxml.jackson.databind.deser.std.JsonNodeDeserializer.deserialize(JsonNodeDeserializer.java:15)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2563)
at com.fasterxml.jackson.databind.ObjectMapper.readTree(ObjectMapper.java:1500)
at com.googlecode.jsonschema2pojo.Schema.create(Schema.java:65)
... 25 more
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5 minutes 3 seconds
[INFO] Finished at: Wed May 30 21:00:03 BST 2012
[INFO] Final Memory: 7M/19M
[INFO] ------------------------------------------------------------------------

Suggestion

In com.googlecode.jsonschema2pojo.Schema.create(java.net.URI) line: 73

we have the URI available. Use that in the exception for more information. E.g.:

throw new GenerationException("Error with schema: " + id, e);

This change requires a new constructor in com.googlecode.jsonschema2pojo.exception.GenerationException.

public GenerationException(String message, Throwable cause) {
    super(message, cause);
}

What version of the product are you using? On what Java version?

0.2.5-SNAPSHOT (Rev 104770c)

java version "1.6.0_31"

Original issue: http://code.google.com/p/jsonschema2pojo/issues/detail?id=51

@joelittlejohn
Copy link
Owner Author

This issue is a duplicate of #50

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant