16 changed files with 256 additions and 132 deletions
@ -1,33 +0,0 @@
|
||||
/* |
||||
* Copyright 2011 the original author or authors. |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package com.jayway.jsonpath; |
||||
|
||||
@SuppressWarnings("serial") |
||||
public class InvalidCriteriaException extends JsonPathException { |
||||
public InvalidCriteriaException() { |
||||
} |
||||
|
||||
public InvalidCriteriaException(String message) { |
||||
super(message); |
||||
} |
||||
|
||||
public InvalidCriteriaException(String message, Throwable cause) { |
||||
super(message, cause); |
||||
} |
||||
|
||||
public InvalidCriteriaException(Throwable cause) { |
||||
super(cause); |
||||
} |
||||
} |
@ -0,0 +1,40 @@
|
||||
package com.jayway.jsonpath.internal.path; |
||||
|
||||
import com.jayway.jsonpath.internal.function.ParamType; |
||||
import com.jayway.jsonpath.internal.function.Parameter; |
||||
|
||||
import java.util.Arrays; |
||||
|
||||
public class ScannerFunctionInverter { |
||||
|
||||
private final RootPathToken path; |
||||
|
||||
public ScannerFunctionInverter(RootPathToken path) { |
||||
this.path = path; |
||||
} |
||||
|
||||
public RootPathToken invert() { |
||||
if (path.isFunctionPath() && path.next() instanceof ScanPathToken) { |
||||
PathToken token = path; |
||||
PathToken prior = null; |
||||
while (null != (token = token.next()) && !(token instanceof FunctionPathToken)) { |
||||
prior = token; |
||||
} |
||||
if (token instanceof FunctionPathToken) { |
||||
prior.setNext(null); |
||||
path.setTail(prior); |
||||
|
||||
Parameter parameter = new Parameter(); |
||||
parameter.setPath(new CompiledPath(path, true)); |
||||
parameter.setType(ParamType.PATH); |
||||
((FunctionPathToken)token).setParameters(Arrays.asList(parameter)); |
||||
RootPathToken functionRoot = new RootPathToken('$'); |
||||
functionRoot.setTail(token); |
||||
functionRoot.setNext(token); |
||||
|
||||
return functionRoot; |
||||
} |
||||
} |
||||
return path; |
||||
} |
||||
} |
@ -0,0 +1,61 @@
|
||||
package com.jayway.jsonpath.internal; |
||||
|
||||
import org.junit.jupiter.api.Test; |
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals; |
||||
|
||||
|
||||
public class JsonFormatterTest { |
||||
|
||||
// Test case for pretty printing a simple JSON object
|
||||
// The input is a simple JSON object
|
||||
// The expected output is the same JSON object with proper indentation
|
||||
@Test |
||||
public void testPrettyPrint_SimpleJson() { |
||||
JsonFormatter jsonFormatter = new JsonFormatter(); |
||||
String input = "{\"name\":\"Vaibhav Ramchandani\",\"age\":23,\"city\":\"Halifax\"}"; |
||||
String actualOutput = jsonFormatter.prettyPrint(input); |
||||
String expectedOutput = "{\n \"name\" : \"Vaibhav Ramchandani\",\n \"age\" : 23,\n \"city\" : \"Halifax\"\n}"; |
||||
assertEquals(expectedOutput.replaceAll("\\s", ""), actualOutput.replaceAll("\\s", "")); |
||||
} |
||||
|
||||
// Test case for pretty printing a JSON object with escaped characters
|
||||
// The input is a JSON object with escaped characters
|
||||
// The expected output is the same JSON object with proper indentation
|
||||
//
|
||||
@Test |
||||
public void testPrettyPrint_JsonWithEscapedCharacters() { |
||||
JsonFormatter jsonFormatter = new JsonFormatter(); |
||||
String input = "{\"message\":\"This is ,\\nJsonPath Repo!\"}"; |
||||
String actualOutput = jsonFormatter.prettyPrint(input); |
||||
String expectedOutput = "{\n \"message\" : \"This is ,\\nJsonPath Repo!\"\n}"; |
||||
assertEquals(expectedOutput.replaceAll("\\s", ""), actualOutput.replaceAll("\\s", "")); |
||||
} |
||||
|
||||
// Test case for pretty printing a JSON array
|
||||
// The input is a JSON array
|
||||
// The expected output is the same JSON array with proper indentation
|
||||
@Test |
||||
public void testPrettyPrint_JsonWithArray() { |
||||
//
|
||||
JsonFormatter jsonFormatter = new JsonFormatter(); |
||||
String input = "[{\"name\":\"Vaibhav R\",\"age\":23},{\"name\":\"Sanskar K\",\"age\":24}]"; |
||||
String actualOutput=jsonFormatter.prettyPrint(input); |
||||
String expectedOutput = "[\n {\n \"name\" : \"Vaibhav R\",\n \"age\" : 23\n },\n {\n \"name\" : \"Sanskar K\",\n \"age\" : 24\n }\n]"; |
||||
assertEquals(expectedOutput.replaceAll("\\s", ""), actualOutput.replaceAll("\\s", "")); |
||||
} |
||||
|
||||
// Test case for pretty printing a JSON object with single quotes
|
||||
// The input is a JSON object with single quotes
|
||||
// The expected output is the same JSON object with proper indentation
|
||||
@Test |
||||
public void testPrettyPrint_JsonWithSingleQuotes() { |
||||
|
||||
JsonFormatter jsonFormatter = new JsonFormatter(); |
||||
String input = "{'name':'Vaibhav Ramchandani','age':23,'city':'Halifax'}"; |
||||
String actualOutput = jsonFormatter.prettyPrint(input); |
||||
String expectedOutput = "{\n 'name' : 'Vaibhav Ramchandani',\n 'age' : 23,\n 'city' : 'Halifax'\n}"; |
||||
assertEquals(expectedOutput.replaceAll("\\s", ""), actualOutput.replaceAll("\\s", "")); |
||||
} |
||||
} |
||||
|
Loading…
Reference in new issue