bolerio / mjson

Lean JSON Library for Java, with a compact, elegant API.
Apache License 2.0
83 stars 24 forks source link

Schema with $ref in spring resource file and NPE #23

Closed Jacuo closed 8 years ago

Jacuo commented 8 years ago
  1. I have my schema file in src/main/resources
  2. In schema i have construction like "$ref": "#/definitions/deleteSchema"
  3. I open schema ResourceLoader resourceLoader ; .... Json.Schema schema = Json.schema(resourceLoader.getResource("classpath:" + jsonSchemaFile).getURI());
  4. I have NPE
Caused by: java.lang.RuntimeException: java.lang.NullPointerException
        at mjson.Json$DefaultSchema.<init>(Json.java:1009) ~[mjson-1.3.jar:na]
        at mjson.Json.schema(Json.java:1035) ~[mjson-1.3.jar:na]
        ... 48 common frames omitted
Caused by: java.lang.NullPointerException: null
        at mjson.Json.resolveRef(Json.java:462) ~[mjson-1.3.jar:na]
        at mjson.Json.expandReferences(Json.java:508) ~[mjson-1.3.jar:na]
        at mjson.Json.expandReferences(Json.java:529) ~[mjson-1.3.jar:na]
        at mjson.Json.expandReferences(Json.java:519) ~[mjson-1.3.jar:na]
        at mjson.Json$DefaultSchema.<init>(Json.java:1006) ~[mjson-1.3.jar:na]
bolerio commented 8 years ago

Can you give me complete schema files that reproduce the problem. It'll save me some time to debug. Also, are you using 1.3 stable or 1.4 snapshot?

bolerio commented 8 years ago

I just added a test with this case (see src/test/resources/schema_with_defs.json) and the unit test in TestSchemas.java

It seem to be working some I'm closing this as working. If you have a use case that shows the problem with the latest code, let's look at it!