vishesh27111
6 months ago
committed by
GitHub
26 changed files with 7264 additions and 110 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1,35 @@ |
|||||||
|
package com.jayway.jsonpath.internal; |
||||||
|
|
||||||
|
import com.jayway.jsonpath.Configuration; |
||||||
|
import static com.jayway.jsonpath.internal.Utils.*; |
||||||
|
import static com.jayway.jsonpath.Option.AS_PATH_LIST; |
||||||
|
|
||||||
|
public class PathEvaluator { |
||||||
|
|
||||||
|
private final Path path; |
||||||
|
private final Configuration configuration; |
||||||
|
|
||||||
|
public PathEvaluator(Path path, Configuration configuration) { |
||||||
|
notNull(path, "path can not be null"); |
||||||
|
notNull(configuration, "configuration can not be null"); |
||||||
|
this.path = path; |
||||||
|
this.configuration = configuration; |
||||||
|
} |
||||||
|
|
||||||
|
public <T> T evaluate(Object jsonObject) { |
||||||
|
boolean optAsPathList = configuration.containsOption(AS_PATH_LIST); |
||||||
|
EvaluationContext evaluationContext = path.evaluate(jsonObject, jsonObject, configuration); |
||||||
|
|
||||||
|
|
||||||
|
return resultByConfiguration(jsonObject, evaluationContext); |
||||||
|
} |
||||||
|
|
||||||
|
private <T> T resultByConfiguration(Object jsonObject, EvaluationContext evaluationContext) { |
||||||
|
if(configuration.containsOption(AS_PATH_LIST)){ |
||||||
|
return (T)evaluationContext.getPathList(); |
||||||
|
} else { |
||||||
|
return (T) jsonObject; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,5 @@ |
|||||||
|
package com.jayway.jsonpath.spi.json; |
||||||
|
|
||||||
|
public interface JsonLengthCalculator { |
||||||
|
int calculateLength(Object obj); |
||||||
|
} |
@ -0,0 +1,34 @@ |
|||||||
|
//package com.jayway.jsonpath.internal;
|
||||||
|
//
|
||||||
|
//import com.jayway.jsonpath.spi.json.JettisonProvider;
|
||||||
|
//import org.junit.Before;
|
||||||
|
//import org.junit.Test;
|
||||||
|
//
|
||||||
|
//import static org.junit.Assert.assertEquals;
|
||||||
|
//import static org.junit.Assert.assertTrue;
|
||||||
|
//
|
||||||
|
//public class JettisonProviderTest {
|
||||||
|
//
|
||||||
|
// private JettisonProvider jsonProvider;
|
||||||
|
//
|
||||||
|
// @Before
|
||||||
|
// public void setUp() {
|
||||||
|
// jsonProvider = new JettisonProvider();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @Test
|
||||||
|
// public void parseValidJsonString() {
|
||||||
|
// //Input json
|
||||||
|
// String jsonString = "{\"name\":\"Vishesh\",\"age\":21}";
|
||||||
|
//
|
||||||
|
// // When parsing a valid JSON string
|
||||||
|
// Object result = jsonProvider.parse(jsonString);
|
||||||
|
//
|
||||||
|
// assertTrue(jsonProvider.isMap(result));
|
||||||
|
//
|
||||||
|
// // expected values
|
||||||
|
// assertEquals("Vishesh", jsonProvider.getMapValue(result, "name"));
|
||||||
|
// assertEquals(21, jsonProvider.getMapValue(result, "age"));
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//}
|
@ -0,0 +1,46 @@ |
|||||||
|
//package com.jayway.jsonpath.internal;
|
||||||
|
//
|
||||||
|
//import com.jayway.jsonpath.spi.json.JsonOrgJsonProvider;
|
||||||
|
//import org.junit.Before;
|
||||||
|
//import org.junit.Test;
|
||||||
|
//
|
||||||
|
//import java.io.ByteArrayInputStream;
|
||||||
|
//import java.io.InputStream;
|
||||||
|
//import java.nio.charset.StandardCharsets;
|
||||||
|
//
|
||||||
|
//import static org.junit.Assert.assertEquals;
|
||||||
|
//import static org.junit.Assert.assertTrue;
|
||||||
|
//
|
||||||
|
//public class JsonOrgJsonProviderTest {
|
||||||
|
// private JsonOrgJsonProvider jsonProvider;
|
||||||
|
// @Before
|
||||||
|
// public void setUp() {
|
||||||
|
// jsonProvider = new JsonOrgJsonProvider();
|
||||||
|
// }
|
||||||
|
// @Test
|
||||||
|
// public void parseValidJsonString() {
|
||||||
|
// //input json
|
||||||
|
// String jsonString = "{\"name\":\"Raj\",\"age\":31}";
|
||||||
|
//
|
||||||
|
// // When parsing a valid JSON string
|
||||||
|
// Object result = jsonProvider.parse(jsonString);
|
||||||
|
//
|
||||||
|
// assertTrue(jsonProvider.isMap(result));
|
||||||
|
// assertEquals("Raj", jsonProvider.getMapValue(result, "name"));
|
||||||
|
// assertEquals(31, jsonProvider.getMapValue(result, "age"));
|
||||||
|
// }
|
||||||
|
// @Test
|
||||||
|
// public void parseValidJsonInputStream() {
|
||||||
|
//
|
||||||
|
// String jsonString = "{\"name\":\"Raj\",\"age\":31}";
|
||||||
|
// InputStream jsonStream = new ByteArrayInputStream(jsonString.getBytes(StandardCharsets.UTF_8));
|
||||||
|
//
|
||||||
|
// // When parsing valid JSON from an InputStream
|
||||||
|
// Object result = jsonProvider.parse(jsonStream, StandardCharsets.UTF_8.name());
|
||||||
|
//
|
||||||
|
// assertTrue(jsonProvider.isMap(result));
|
||||||
|
// // expected values
|
||||||
|
// assertEquals("Raj", jsonProvider.getMapValue(result, "name"));
|
||||||
|
// assertEquals(31, jsonProvider.getMapValue(result, "age"));
|
||||||
|
// }
|
||||||
|
//}
|
@ -0,0 +1,42 @@ |
|||||||
|
//package com.jayway.jsonpath.internal;
|
||||||
|
//
|
||||||
|
//import com.jayway.jsonpath.Configuration;
|
||||||
|
//import com.jayway.jsonpath.TypeRef;
|
||||||
|
//import com.jayway.jsonpath.spi.mapper.TapestryMappingProvider;
|
||||||
|
//import org.junit.Before;
|
||||||
|
//import org.junit.Test;
|
||||||
|
//
|
||||||
|
//import java.util.List;
|
||||||
|
//
|
||||||
|
//import static org.junit.Assert.assertNull;
|
||||||
|
//import static org.junit.Assert.fail;
|
||||||
|
//
|
||||||
|
//public class TapestryMappingProviderTest {
|
||||||
|
// private TapestryMappingProvider mappingProvider;
|
||||||
|
// private Configuration configuration;
|
||||||
|
// @Before
|
||||||
|
// public void setUp() {
|
||||||
|
// mappingProvider = new TapestryMappingProvider();
|
||||||
|
// configuration = Configuration.defaultConfiguration();
|
||||||
|
// }
|
||||||
|
// @Test
|
||||||
|
// public void mapNullSourceToNullTarget() {
|
||||||
|
// Object source = null;
|
||||||
|
//
|
||||||
|
// Object result = mappingProvider.map(source, List.class, configuration);
|
||||||
|
//
|
||||||
|
// //result should be null
|
||||||
|
// assertNull(result);
|
||||||
|
// }
|
||||||
|
// @Test
|
||||||
|
// public void mapArrayToJsonRef() {
|
||||||
|
// String[] source = new String[]{"Red", "Green", "Blue"};
|
||||||
|
//
|
||||||
|
// try {
|
||||||
|
// Object result = mappingProvider.map(source, new TypeRef<List<String>>() {}, configuration);
|
||||||
|
// fail("Expected UnsupportedOperationException");
|
||||||
|
// } catch (UnsupportedOperationException e) {
|
||||||
|
// // UnsupportedOperationException should be thrown
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//}
|
Loading…
Reference in new issue