Repository: johnzon
Updated Branches:
  refs/heads/master 1799768f6 -> 218a8abfc


JOHNZON-157 don't use an actual state as default in our parsers to avoid errors 
when caller assumes the state (event)


Project: http://git-wip-us.apache.org/repos/asf/johnzon/repo
Commit: http://git-wip-us.apache.org/repos/asf/johnzon/commit/218a8abf
Tree: http://git-wip-us.apache.org/repos/asf/johnzon/tree/218a8abf
Diff: http://git-wip-us.apache.org/repos/asf/johnzon/diff/218a8abf

Branch: refs/heads/master
Commit: 218a8abfceab97864fbb77889056c7759b3acdd5
Parents: 1799768
Author: Romain Manni-Bucau <rmannibu...@gmail.com>
Authored: Mon Feb 12 10:58:13 2018 +0100
Committer: Romain Manni-Bucau <rmannibu...@gmail.com>
Committed: Mon Feb 12 10:58:13 2018 +0100

----------------------------------------------------------------------
 .../apache/johnzon/core/JsonInMemoryParser.java    |  3 +++
 .../apache/johnzon/core/JsonStreamParserImpl.java  | 17 ++++++++++-------
 .../org/apache/johnzon/core/JsonParserTest.java    |  2 --
 3 files changed, 13 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/johnzon/blob/218a8abf/johnzon-core/src/main/java/org/apache/johnzon/core/JsonInMemoryParser.java
----------------------------------------------------------------------
diff --git 
a/johnzon-core/src/main/java/org/apache/johnzon/core/JsonInMemoryParser.java 
b/johnzon-core/src/main/java/org/apache/johnzon/core/JsonInMemoryParser.java
index 31e767d..f94e437 100644
--- a/johnzon-core/src/main/java/org/apache/johnzon/core/JsonInMemoryParser.java
+++ b/johnzon-core/src/main/java/org/apache/johnzon/core/JsonInMemoryParser.java
@@ -173,6 +173,9 @@ class JsonInMemoryParser extends JohnzonJsonParserImpl {
 
     @Override
     public Event current() {
+        if (currentEvent == null && hasNext()) {
+            next();
+        }
         return currentEvent;
     }
 

http://git-wip-us.apache.org/repos/asf/johnzon/blob/218a8abf/johnzon-core/src/main/java/org/apache/johnzon/core/JsonStreamParserImpl.java
----------------------------------------------------------------------
diff --git 
a/johnzon-core/src/main/java/org/apache/johnzon/core/JsonStreamParserImpl.java 
b/johnzon-core/src/main/java/org/apache/johnzon/core/JsonStreamParserImpl.java
index aa5ca1b..44c4ee9 100644
--- 
a/johnzon-core/src/main/java/org/apache/johnzon/core/JsonStreamParserImpl.java
+++ 
b/johnzon-core/src/main/java/org/apache/johnzon/core/JsonStreamParserImpl.java
@@ -62,7 +62,7 @@ public class JsonStreamParserImpl extends 
JohnzonJsonParserImpl implements JsonC
     //we use a byte here, because comparing bytes
     //is more efficient than comparing enums
     //Additionally we handle internally two more event: COMMA_EVENT and 
KEY_SEPARATOR_EVENT
-    private byte previousEvent = 0;
+    private byte previousEvent = -1;
 
     //this buffer is used to store current String or Number value in case that
     //within the value a buffer boundary is crossed or the string contains 
escaped characters
@@ -344,6 +344,9 @@ public class JsonStreamParserImpl extends 
JohnzonJsonParserImpl implements JsonC
 
     @Override
     public Event current() {
+        if (previousEvent < 0 && hasNext()) {
+            next();
+        }
         return previousEvent >= 0 && previousEvent < Event.values().length
                 ? Event.values()[previousEvent]
                 : null;
@@ -357,7 +360,7 @@ public class JsonStreamParserImpl extends 
JohnzonJsonParserImpl implements JsonC
             throw new NoSuchElementException();
         }
 
-        if (previousEvent != 0 && currentStructureElement == null) {
+        if (previousEvent > 0 && currentStructureElement == null) {
             throw uexc("Unexpected end of structure");
         }
 
@@ -459,7 +462,7 @@ public class JsonStreamParserImpl extends 
JohnzonJsonParserImpl implements JsonC
     private Event handleStartObject() {
 
         //last event must one of the following-> : , [
-        if (previousEvent != 0 && previousEvent != KEY_SEPARATOR_EVENT && 
previousEvent != START_ARRAY && previousEvent != COMMA_EVENT) {
+        if (previousEvent > 0 && previousEvent != KEY_SEPARATOR_EVENT && 
previousEvent != START_ARRAY && previousEvent != COMMA_EVENT) {
             throw uexc("Expected : , [");
         }
 
@@ -499,7 +502,7 @@ public class JsonStreamParserImpl extends 
JohnzonJsonParserImpl implements JsonC
     private Event handleStartArray() {
 
         //last event must one of the following-> : , [
-        if (previousEvent != 0 && previousEvent != KEY_SEPARATOR_EVENT && 
previousEvent != START_ARRAY && previousEvent != COMMA_EVENT) {
+        if (previousEvent > 0 && previousEvent != KEY_SEPARATOR_EVENT && 
previousEvent != START_ARRAY && previousEvent != COMMA_EVENT) {
             throw uexc("Expected : , [");
         }
 
@@ -673,8 +676,8 @@ public class JsonStreamParserImpl extends 
JohnzonJsonParserImpl implements JsonC
         //always the beginning quote of a key or value  
 
         //last event must one of the following-> : { [ ,
-        if (previousEvent != KEY_SEPARATOR_EVENT && previousEvent != 
START_OBJECT && previousEvent != START_ARRAY
-                && previousEvent != COMMA_EVENT) {
+        if (previousEvent != -1 && (previousEvent != KEY_SEPARATOR_EVENT && 
previousEvent != START_OBJECT && previousEvent != START_ARRAY
+                && previousEvent != COMMA_EVENT)) {
             throw uexc("Expected : { [ ,");
         }
         //starting quote already consumed
@@ -818,7 +821,7 @@ public class JsonStreamParserImpl extends 
JohnzonJsonParserImpl implements JsonC
     private Event handleLiteral() {
 
         //last event must one of the following-> : , [
-        if (previousEvent != KEY_SEPARATOR_EVENT && previousEvent != 
START_ARRAY && previousEvent != COMMA_EVENT) {
+        if (previousEvent != -1 && previousEvent != KEY_SEPARATOR_EVENT && 
previousEvent != START_ARRAY && previousEvent != COMMA_EVENT) {
             throw uexc("Expected : , [");
         }
 

http://git-wip-us.apache.org/repos/asf/johnzon/blob/218a8abf/johnzon-core/src/test/java/org/apache/johnzon/core/JsonParserTest.java
----------------------------------------------------------------------
diff --git 
a/johnzon-core/src/test/java/org/apache/johnzon/core/JsonParserTest.java 
b/johnzon-core/src/test/java/org/apache/johnzon/core/JsonParserTest.java
index 9231853..c4147a9 100644
--- a/johnzon-core/src/test/java/org/apache/johnzon/core/JsonParserTest.java
+++ b/johnzon-core/src/test/java/org/apache/johnzon/core/JsonParserTest.java
@@ -26,8 +26,6 @@ import static org.junit.Assert.fail;
 
 import java.io.ByteArrayInputStream;
 import java.io.CharArrayReader;
-import java.io.File;
-import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.StringReader;

Reply via email to