Example usage for com.fasterxml.jackson.databind JsonMappingException getLocation

List of usage examples for com.fasterxml.jackson.databind JsonMappingException getLocation

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind JsonMappingException getLocation.

Prototype

public JsonLocation getLocation() 

Source Link

Usage

From source file:com.addthis.codec.jackson.Jackson.java

public static JsonMappingException maybeImproveLocation(JsonLocation wrapLoc, JsonMappingException cause) {
    JsonLocation exLoc = cause.getLocation();
    if (isRealLocation(wrapLoc) && !isRealLocation(exLoc)) {
        if (wrapLoc.getSourceRef() instanceof ConfigValue) {
            ConfigValue locRef = (ConfigValue) wrapLoc.getSourceRef();
            List<JsonMappingException.Reference> paths = cause.getPath();
            for (JsonMappingException.Reference path : paths) {
                if (locRef instanceof ConfigObject) {
                    String fieldName = path.getFieldName();
                    ConfigObject locRefObject = (ConfigObject) locRef;
                    if (locRefObject.containsKey(fieldName)) {
                        locRef = locRefObject.get(fieldName);
                    } else {
                        break;
                    }/*from  www.ja  v  a  2s .  c  om*/
                } else if (locRef instanceof ConfigList) {
                    int fieldIndex = path.getIndex();
                    ConfigList locRefList = (ConfigList) locRef;
                    if ((fieldIndex >= 0) && (locRefList.size() > fieldIndex)) {
                        locRef = locRefList.get(fieldIndex);
                    } else {
                        break;
                    }
                } else {
                    break;
                }
            }
            if (locRef != wrapLoc.getSourceRef()) {
                wrapLoc = fromConfigValue(locRef);
            }
        }
        List<JsonMappingException.Reference> paths = Lists.reverse(cause.getPath());
        if (!paths.isEmpty()) {
            JsonMappingException withLoc = new JsonMappingException(rootMessage(cause), wrapLoc, cause);
            for (JsonMappingException.Reference path : paths) {
                withLoc.prependPath(path);
            }
            return withLoc;
        } else {
            return new JsonMappingException(rootMessage(cause), wrapLoc, cause);
        }
    }
    return cause;
}

From source file:com.addthis.codec.jackson.Jackson.java

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;
                }//from  ww w  . j  ava  2 s .  com
                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;
        }
    }
    return cause;
}