}
}
public static IOException maybeUnwrapPath(String pathToSkip, IOException cause) {
if ((pathToSkip != null) && (cause instanceof JsonMappingException)) {
JsonMappingException mappingException = (JsonMappingException) cause;
List<JsonMappingException.Reference> paths = mappingException.getPath();
if (!paths.isEmpty()) {
Iterator<String> pathIterator = dotSplitter.split(pathToSkip).iterator();
Iterator<JsonMappingException.Reference> refIterator = paths.iterator();
while (pathIterator.hasNext()) {
String pathToSkipPart = pathIterator.next();
if (!refIterator.hasNext()) {
return cause;
}
String nextRefField = refIterator.next().getFieldName();
if (!pathToSkipPart.equals(nextRefField)) {
return cause;
}
}
JsonMappingException unwrapped = new JsonMappingException(rootMessage(mappingException),
mappingException.getLocation(),
mappingException.getCause());
if (refIterator.hasNext()) {
List<JsonMappingException.Reference> remainingRefs = Lists.newArrayList(refIterator);
for (JsonMappingException.Reference reference : Lists.reverse(remainingRefs)) {
unwrapped.prependPath(reference);
}
}
return unwrapped;
}
}