use of com.jayway.jsonpath.JsonPathException in project JsonPath by jayway.
the class Utils method unescape.
public static String unescape(String str) {
if (str == null) {
return null;
}
int len = str.length();
StringWriter writer = new StringWriter(len);
StringBuilder unicode = new StringBuilder(4);
boolean hadSlash = false;
boolean inUnicode = false;
for (int i = 0; i < len; i++) {
char ch = str.charAt(i);
if (inUnicode) {
unicode.append(ch);
if (unicode.length() == 4) {
try {
int value = Integer.parseInt(unicode.toString(), 16);
writer.write((char) value);
unicode.setLength(0);
inUnicode = false;
hadSlash = false;
} catch (NumberFormatException nfe) {
throw new JsonPathException("Unable to parse unicode value: " + unicode, nfe);
}
}
continue;
}
if (hadSlash) {
hadSlash = false;
switch(ch) {
case '\\':
writer.write('\\');
break;
case '\'':
writer.write('\'');
break;
case '\"':
writer.write('"');
break;
case 'r':
writer.write('\r');
break;
case 'f':
writer.write('\f');
break;
case 't':
writer.write('\t');
break;
case 'n':
writer.write('\n');
break;
case 'b':
writer.write('\b');
break;
case 'u':
{
inUnicode = true;
break;
}
default:
writer.write(ch);
break;
}
continue;
} else if (ch == '\\') {
hadSlash = true;
continue;
}
writer.write(ch);
}
if (hadSlash) {
writer.write('\\');
}
return writer.toString();
}
use of com.jayway.jsonpath.JsonPathException in project JsonPath by jayway.
the class IsJson method describeMismatchSafely.
@Override
protected void describeMismatchSafely(T json, Description mismatchDescription) {
try {
ReadContext context = parse(json);
jsonMatcher.describeMismatch(context, mismatchDescription);
} catch (JsonPathException e) {
buildMismatchDescription(json, mismatchDescription, e);
} catch (IOException e) {
buildMismatchDescription(json, mismatchDescription, e);
}
}
use of com.jayway.jsonpath.JsonPathException in project qpp-conversion-tool by CMSgov.
the class ValidationServiceImpl method convertQppValidationErrorsToQrda.
/**
* Converts the QPP error returned from the validation API to QRDA3 errors
*
* @param validationResponse The JSON response containing a QPP error.
* @param wrapper The QPP that resulted in the QPP error.
* @return The QRDA3 errors.
*/
AllErrors convertQppValidationErrorsToQrda(String validationResponse, JsonWrapper wrapper) {
AllErrors errors = new AllErrors();
if (validationResponse == null) {
return errors;
}
Error error = getError(validationResponse);
error.getDetails().forEach(detail -> {
detail.setMessage(SV_LABEL + detail.getMessage());
String newPath = UNABLE_PROVIDE_XPATH;
try {
newPath = PathCorrelator.prepPath(detail.getPath(), wrapper);
} catch (ClassCastException | JsonPathException exc) {
API_LOG.warn("Failed to convert from json path to an XPath.", exc);
}
detail.setPath(newPath);
});
errors.addError(error);
return errors;
}
Aggregations