Browse Source

update json-smart to 2.0

pull/42/head
Jochen Berger 10 years ago
parent
commit
f1eb8a85d1
  1. 23
      json-path/src/main/java/com/jayway/jsonpath/internal/spi/json/JsonSmartJsonProvider.java
  2. 2
      pom.xml

23
json-path/src/main/java/com/jayway/jsonpath/internal/spi/json/JsonSmartJsonProvider.java

@ -16,9 +16,11 @@ package com.jayway.jsonpath.internal.spi.json;
import com.jayway.jsonpath.InvalidJsonException; import com.jayway.jsonpath.InvalidJsonException;
import com.jayway.jsonpath.spi.json.Mode; import com.jayway.jsonpath.spi.json.Mode;
import net.minidev.json.JSONArray; import net.minidev.json.JSONArray;
import net.minidev.json.JSONObject; import net.minidev.json.JSONObject;
import net.minidev.json.parser.ContainerFactory; import net.minidev.json.mapper.AMapper;
import net.minidev.json.mapper.DefaultMapperOrdered;
import net.minidev.json.parser.JSONParser; import net.minidev.json.parser.JSONParser;
import net.minidev.json.parser.ParseException; import net.minidev.json.parser.ParseException;
@ -30,10 +32,9 @@ import java.util.Map;
public class JsonSmartJsonProvider extends AbstractJsonProvider { public class JsonSmartJsonProvider extends AbstractJsonProvider {
private Mode mode; private final Mode mode;
private ContainerFactory containerFactory = ContainerFactory.FACTORY_ORDERED; private final static AMapper<?> orderedMapper = DefaultMapperOrdered.DEFAULT;
//private ContainerFactory containerFactory = ContainerFactory.FACTORY_SIMPLE;
public JsonSmartJsonProvider() { public JsonSmartJsonProvider() {
this(Mode.SLACK); this(Mode.SLACK);
@ -43,17 +44,17 @@ public class JsonSmartJsonProvider extends AbstractJsonProvider {
this.mode = mode; this.mode = mode;
} }
public Map<String, Object> createMap() { public Object createMap() {
return containerFactory.createObjectContainer(); return orderedMapper.createObject();
} }
public List<Object> createArray() { public Object createArray() {
return containerFactory.createArrayContainer(); return orderedMapper.createArray();
} }
public Object parse(String json) { public Object parse(String json) {
try { try {
return createParser().parse(json, containerFactory); return createParser().parse(json, orderedMapper);
} catch (ParseException e) { } catch (ParseException e) {
throw new InvalidJsonException(e); throw new InvalidJsonException(e);
} }
@ -62,7 +63,7 @@ public class JsonSmartJsonProvider extends AbstractJsonProvider {
@Override @Override
public Object parse(Reader jsonReader) throws InvalidJsonException { public Object parse(Reader jsonReader) throws InvalidJsonException {
try { try {
return createParser().parse(jsonReader, containerFactory); return createParser().parse(jsonReader, orderedMapper);
} catch (ParseException e) { } catch (ParseException e) {
throw new InvalidJsonException(e); throw new InvalidJsonException(e);
} }
@ -71,7 +72,7 @@ public class JsonSmartJsonProvider extends AbstractJsonProvider {
@Override @Override
public Object parse(InputStream jsonStream) throws InvalidJsonException { public Object parse(InputStream jsonStream) throws InvalidJsonException {
try { try {
return createParser().parse(new InputStreamReader(jsonStream), containerFactory); return createParser().parse(new InputStreamReader(jsonStream), orderedMapper);
} catch (ParseException e) { } catch (ParseException e) {
throw new InvalidJsonException(e); throw new InvalidJsonException(e);
} }

2
pom.xml

@ -61,7 +61,7 @@
<commons-io.version>2.4</commons-io.version> <commons-io.version>2.4</commons-io.version>
<hamcrest.version>1.3</hamcrest.version> <hamcrest.version>1.3</hamcrest.version>
<jackson.version>2.4.0</jackson.version> <jackson.version>2.4.0</jackson.version>
<json-smart.version>1.2</json-smart.version> <json-smart.version>2.0</json-smart.version>
</properties> </properties>
<scm> <scm>
<url>http://github.com/jayway/JsonPath/tree/${scm.branch}</url> <url>http://github.com/jayway/JsonPath/tree/${scm.branch}</url>

Loading…
Cancel
Save