-
-
Notifications
You must be signed in to change notification settings - Fork 76
Support reading multiple JSON syntax blocks in a single input (#269) #272
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,10 @@ public JSONParserInputStream(int permissiveMode) { | |
super(permissiveMode); | ||
} | ||
|
||
public JSONParserInputStream(InputStream in, int permissiveMode) { | ||
super(new InputStreamReader(in, StandardCharsets.UTF_8), permissiveMode); | ||
} | ||
|
||
/** | ||
* use to return Primitive Type, or String, Or JsonObject or JsonArray generated by a | ||
* ContainerFactory | ||
|
@@ -54,13 +58,4 @@ public <T> T parse(InputStream in, JsonReaderI<T> mapper) | |
// | ||
return super.parse(i2, mapper); | ||
} | ||
|
||
// | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. double check lines offset ans preserve some empty lines here probably should keep 5 out of 9 |
||
// | ||
// | ||
// | ||
// | ||
// | ||
// | ||
// | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,8 +28,6 @@ | |
* @see JSONParserReader | ||
*/ | ||
abstract class JSONParserStream extends JSONParserBase { | ||
// len | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do not drop those offset empty lines. |
||
// | ||
public JSONParserStream(int permissiveMode) { | ||
super(permissiveMode); | ||
} | ||
|
@@ -112,26 +110,8 @@ protected void readString() throws ParseException, IOException { | |
throw new ParseException(pos, ERROR_UNEXPECTED_CHAR, c); | ||
} | ||
sb.clear(); | ||
// | ||
// | ||
// | ||
// | ||
// | ||
// | ||
// | ||
// | ||
// | ||
// | ||
|
||
/* assert (c == '\"' || c == '\'') */ | ||
readString2(); | ||
} | ||
|
||
// | ||
// | ||
// | ||
// | ||
// | ||
// | ||
// | ||
// | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
json-smart/src/main/java/net/minidev/json/parser/MultipleJsonParser.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package net.minidev.json.parser; | ||
|
||
import java.io.InputStream; | ||
import java.io.Reader; | ||
import net.minidev.json.JSONValue; | ||
import net.minidev.json.writer.JsonReaderI; | ||
|
||
/** | ||
* json-smart will parse multiple json separated by blank or line break character. | ||
* | ||
* <p>multiple json example: <br> | ||
* {"json1": "value1"} {"json2": "value2"} <br> | ||
* or <br> | ||
* [{"json1-key1": "value1"}] [{"json2": "value2"}] | ||
*/ | ||
public class MultipleJsonParser { | ||
|
||
private final JSONParserBase jsonParser; | ||
|
||
public MultipleJsonParser(byte[] in, int permissiveMode) { | ||
this.jsonParser = new JSONParserByteArray(in, permissiveMode); | ||
} | ||
|
||
public MultipleJsonParser(InputStream in, int permissiveMode) { | ||
this.jsonParser = new JSONParserInputStream(in, permissiveMode); | ||
} | ||
|
||
public MultipleJsonParser(Reader in, int permissiveMode) { | ||
this.jsonParser = new JSONParserReader(in, permissiveMode); | ||
} | ||
|
||
public MultipleJsonParser(String in, int permissiveMode) { | ||
this.jsonParser = new JSONParserString(in, permissiveMode); | ||
} | ||
|
||
/** | ||
* Parse next json with defaultReader <br> | ||
* use to return Primitive Type, or String, Or JsonObject or JsonArray generated by a | ||
* ContainerFactory | ||
*/ | ||
public Object parseNext() throws ParseException { | ||
return jsonParser.parseNext(JSONValue.defaultReader.DEFAULT); | ||
} | ||
|
||
/** | ||
* Parse next json with target JsonReaderI <br> | ||
* use to return Primitive Type, or String, Or JsonObject or JsonArray generated by a | ||
* ContainerFactory | ||
*/ | ||
public <T> T parseNext(JsonReaderI<T> mapper) throws ParseException { | ||
return this.jsonParser.parseNext(mapper); | ||
} | ||
|
||
/** Parse next json with target Class */ | ||
public <T> T parseNext(Class<T> mapTo) throws ParseException { | ||
return this.jsonParser.parseNext(JSONValue.defaultReader.getMapper(mapTo)); | ||
} | ||
|
||
/** | ||
* Checks if there is another JSON value available in the input. | ||
* | ||
* @return true if another JSON value exists, false otherwise | ||
*/ | ||
public boolean hasNext() { | ||
return this.jsonParser.hasNext(); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's important that we maintain the blank lines in this file. They aren't 'empty' code; they're there to synchronize line numbers with similar files. In this pull request, you've added six lines and removed seven, which has broken this synchronization. Please adjust your changes to restore the correct line number offset.