Browse Source

fix issue json-path#762 and add some test cases. (#821)

* fix issue json-path#762

* fix issue json-path#762
pull/797/merge
Nancyzxy 3 years ago committed by GitHub
parent
commit
5340aff05b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      json-path/src/main/java/com/jayway/jsonpath/spi/json/JsonSmartJsonProvider.java
  2. 20
      json-path/src/test/java/com/jayway/jsonpath/Issue_762.java

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

@ -83,6 +83,8 @@ public class JsonSmartJsonProvider extends AbstractJsonProvider {
return JSONObject.toJSONString((Map<String, ?>) obj, JSONStyle.LT_COMPRESS);
} else if (obj instanceof List) {
return JSONArray.toJSONString((List<?>) obj, JSONStyle.LT_COMPRESS);
} else if (obj instanceof Number || obj instanceof Boolean){
return JSONValue.toJSONString(obj);
} else {
throw new UnsupportedOperationException(obj.getClass().getName() + " can not be converted to JSON");
}

20
json-path/src/test/java/com/jayway/jsonpath/Issue_762.java

@ -0,0 +1,20 @@
package com.jayway.jsonpath;
import org.junit.Test;
import static com.jayway.jsonpath.BaseTest.JSON_DOCUMENT;
/**
* test for issue 762
*/
public class Issue_762 {
@Test
public void testParseJsonValue(){
assert(JsonPath.parse(5).jsonString().equals("5"));
assert(JsonPath.parse(5.0).jsonString().equals("5.0"));
assert(JsonPath.parse(true).jsonString().equals("true"));
assert(JsonPath.parse(false).jsonString().equals("false"));
}
}
Loading…
Cancel
Save