Doesn't generate POJOs when there is a JSON Schema

727 views
Skip to first unread message

nickolov...@gmail.com

unread,
Aug 15, 2014, 4:41:56 AM8/15/14
to jsonschema...@googlegroups.com
Hello All, 

I am trying to generate POJOs having the following type of schema:

{

    "definitions": {
           "mytype": {
                      // here goes the schema stuff
                      "description": "blah, blah",
                      "type": "object",
                      "properties": {// the actual properties}
           }
     }
}

the ant target runs but doesn't produce any output or errors.
When I strip down the first lines : 

{

    "definitions": {
           "mytype":

it seems to be working, however I can't do this for all my files because there are more complex structures in the schemas and I am actually not allowed to change them.

Any advises are widely welcome.

Kind Regards,
Vess

nickolov...@gmail.com

unread,
Aug 15, 2014, 5:05:37 AM8/15/14
to jsonschema...@googlegroups.com, nickolov...@gmail.com
The precise stack trace comes when I try to run the ant target on a folder not on a single file: 

BUILD FAILED
java.lang.IllegalArgumentException: Path not present: definitions
        at org.jsonschema2pojo.FragmentResolver.resolve(FragmentResolver.java:54)
        at org.jsonschema2pojo.FragmentResolver.resolve(FragmentResolver.java:31)
        at org.jsonschema2pojo.SchemaStore.create(SchemaStore.java:50)
        at org.jsonschema2pojo.SchemaStore.create(SchemaStore.java:93)
        at org.jsonschema2pojo.rules.SchemaRule.apply(SchemaRule.java:59)
        at org.jsonschema2pojo.rules.SchemaRule.apply(SchemaRule.java:30)
        at org.jsonschema2pojo.rules.PropertyRule.apply(PropertyRule.java:74)
        at org.jsonschema2pojo.rules.PropertyRule.apply(PropertyRule.java:40)
        at org.jsonschema2pojo.rules.PropertiesRule.apply(PropertiesRule.java:60)
        at org.jsonschema2pojo.rules.PropertiesRule.apply(PropertiesRule.java:31)
        at org.jsonschema2pojo.rules.ObjectRule.apply(ObjectRule.java:105)
        at org.jsonschema2pojo.rules.ObjectRule.apply(ObjectRule.java:55)
        at org.jsonschema2pojo.rules.TypeRule.apply(TypeRule.java:97)
        at org.jsonschema2pojo.rules.TypeRule.apply(TypeRule.java:33)
        at org.jsonschema2pojo.rules.SchemaRule.apply(SchemaRule.java:73)
        at org.jsonschema2pojo.rules.SchemaRule.apply(SchemaRule.java:66)
        at org.jsonschema2pojo.rules.SchemaRule.apply(SchemaRule.java:30)
        at org.jsonschema2pojo.SchemaMapper.generate(SchemaMapper.java:88)
        at org.jsonschema2pojo.Jsonschema2Pojo.generateRecursive(Jsonschema2Pojo.java:104)
        at org.jsonschema2pojo.Jsonschema2Pojo.generate(Jsonschema2Pojo.java:68)
        at org.jsonschema2pojo.ant.Jsonschema2PojoTask.execute(Jsonschema2PojoTask.java:139)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
        at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at org.apache.tools.ant.Target.execute(Target.java:390)
        at org.apache.tools.ant.Target.performTasks(Target.java:411)
        at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
        at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
        at org.apache.tools.ant.Main.runBuild(Main.java:809)
        at org.apache.tools.ant.Main.startAnt(Main.java:217)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)

Joe Littlejohn

unread,
Aug 15, 2014, 6:22:29 AM8/15/14
to jsonschema...@googlegroups.com, nickolov...@gmail.com
Apologies if I've misunderstood what your project looks like, but as far as I can tell you don't have any schemas (hence there's nothing to validate). The definitions must be referenced in some way to form an actual schema.

Here's an example from the spec:

{
    "type": "array",
    "items": { "$ref": "#/definitions/positiveInteger" },
    "definitions": {
        "positiveInteger": {
            "type": "integer",
            "minimum": 0,
            "exclusiveMinimum": true
        }
    }
}

As you can see, the schema uses a fragment from the "definitions" object, and this means the rules in this fragment are actually applied. With the definitions alone (as in the example you have given), there is no schema, only definitions.

You mention that when you use the folder (instead of individual file) as the target you get this error. Is it possible that you have another file in the folder that uses a ref like "$ref" : "#/definitions/mytype"? Based on the stack trace, it looks as if you have used a ref like this in a file, but the json object in that file has no node called "definitions".




--
You received this message because you are subscribed to the Google Groups "jsonschema2pojo-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jsonschema2pojo-...@googlegroups.com.
Visit this group at http://groups.google.com/group/jsonschema2pojo-users.
For more options, visit https://groups.google.com/d/optout.

Vesselin Nickolov

unread,
Aug 15, 2014, 6:30:38 AM8/15/14
to Joe Littlejohn, jsonschema...@googlegroups.com
Thank you for the reply.

As far as I found, the currently supported schema version is draft-03 but the files I've got are in draft-04.
This was the initial problem.

Thank you once again.
--
Best Regards
Vesselin Nickolov

Phone: +359 8 88 79 88 54
Skype: rancidvess
Reply all
Reply to author
Forward
0 new messages