[bug] Parser is not working when using json from string source instead of file/classpath
JRDG opened this issue · 2 comments
JRDG commented
Hi! I encounter a bug while using the library, it seems that, despite having a constructor allowing you to use a string variable as the json source:
public $RefParser(String json) {
this.json = json;
this.file = null;
this.uri = null;
}It is not working properly when executing .dereference() method.
Expected result:
- Json is parsed without errors
Actual result:
- Null pointer exception
java.lang.NullPointerException: null
--
at io.zenwave360.jsonrefparser.$RefParser.dereference($RefParser.java:203) ~[json-schema-ref-parser-jvm-0.8.1.jar:?]
at io.zenwave360.jsonrefparser.$RefParser.dereference($RefParser.java:130) ~[json-schema-ref-parser-jvm-0.8.1.jar:?]
Caused by:
- When using json string constructor, the variable
this.uriis null and errors occurs on$RefParser.java:203:currentFileURL.toString()
How to reproduce:
- Create a $RefParser object using
public $RefParser(String json)constructor - Call
.dereference()method.
Possible solutions:
- Assigning a dummy URI object to
this.uricould solve the problem, underparse()method, something like (not tested):- from:
public $RefParser parse() throws IOException { if(file != null) { refs = new $Refs(Parser.parse(file), uri); } else if (uri != null) { refs = new $Refs(Parser.parse(uri), uri); } else { refs = new $Refs(Parser.parse(json)); } return this; }
- to:
public $RefParser parse() throws IOException { if(file != null) { refs = new $Refs(Parser.parse(file), uri); } else if (uri != null) { refs = new $Refs(Parser.parse(uri), uri); } else { refs = new $Refs(Parser.parse(json)); this.uri = new URI("."); } return this; }
Thanks!
ivangsa commented
ivangsa commented
Released in v0.8.2.
Thanks again for your time reporting this..