From e5f210f6a17b13fd9c177f4f07e5a7acccebb880 Mon Sep 17 00:00:00 2001 From: jmlamare Date: Thu, 30 Jun 2016 12:58:32 +0200 Subject: [PATCH] Jettison Integration --- .../jayway/jsonpath/spi/json/JettisonProvider.java | 13 ++++++++++--- .../java/com/jayway/jsonpath/ReadContextTest.java | 3 +-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/json-path/src/main/java/com/jayway/jsonpath/spi/json/JettisonProvider.java b/json-path/src/main/java/com/jayway/jsonpath/spi/json/JettisonProvider.java index 86261763..110709b7 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/spi/json/JettisonProvider.java +++ b/json-path/src/main/java/com/jayway/jsonpath/spi/json/JettisonProvider.java @@ -14,6 +14,7 @@ */ package com.jayway.jsonpath.spi.json; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; @@ -23,9 +24,7 @@ import java.util.Iterator; import java.util.List; import java.util.NoSuchElementException; -import org.apache.commons.io.IOUtils; import org.codehaus.jettison.json.JSONException; - import com.jayway.jsonpath.InvalidJsonException; public class JettisonProvider extends AbstractJsonProvider @@ -219,7 +218,14 @@ public class JettisonProvider extends AbstractJsonProvider { try { - return parse(new JettisonTokener(IOUtils.toString(jsonStream, charset))); + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + byte[] buffer = new byte[1024]; + int size; + while( (size=jsonStream.read(buffer))>0 ) + { + stream.write(buffer, 0, size); + } + return parse(new JettisonTokener(new String(stream.toByteArray(), charset))); } catch( IOException ioe ) { @@ -241,6 +247,7 @@ public class JettisonProvider extends AbstractJsonProvider return ((org.codehaus.jettison.json.JSONObject)obj).toString(2); } return String.valueOf(obj); + //return "\"" + String.valueOf(obj).replaceAll("\"", "\\\"") + "\""; } catch( org.codehaus.jettison.json.JSONException jsonException ) { diff --git a/json-path/src/test/java/com/jayway/jsonpath/ReadContextTest.java b/json-path/src/test/java/com/jayway/jsonpath/ReadContextTest.java index 12d5b554..0edd5ef2 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/ReadContextTest.java +++ b/json-path/src/test/java/com/jayway/jsonpath/ReadContextTest.java @@ -16,8 +16,7 @@ public class ReadContextTest extends BaseTest { String jsonString2 = using(JACKSON_CONFIGURATION).parse(JSON_BOOK_DOCUMENT).jsonString(); String jsonString3 = using(JACKSON_JSON_NODE_CONFIGURATION).parse(JSON_BOOK_DOCUMENT).jsonString(); String jsonString4 = using(GSON_CONFIGURATION).parse(JSON_BOOK_DOCUMENT).jsonString(); - String jsonString5 = using(JETTISON_CONFIGURATION).parse(JSON_BOOK_DOCUMENT).jsonString(); - + Assertions.assertThat(jsonString1).isEqualTo(expected); Assertions.assertThat(jsonString2).isEqualTo(expected); Assertions.assertThat(jsonString3).isEqualTo(expected);