Browse Source

Jettison Integration

pull/244/head
jmlamare 9 years ago
parent
commit
e5f210f6a1
  1. 13
      json-path/src/main/java/com/jayway/jsonpath/spi/json/JettisonProvider.java
  2. 1
      json-path/src/test/java/com/jayway/jsonpath/ReadContextTest.java

13
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 )
{

1
json-path/src/test/java/com/jayway/jsonpath/ReadContextTest.java

@ -16,7 +16,6 @@ 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);

Loading…
Cancel
Save