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

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

Introduction

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

Prototype

public JsonMappingException(String paramString, JsonLocation paramJsonLocation, Throwable paramThrowable) 

Source Link

Usage

From source file:fi.hsl.parkandride.front.geojson.GeojsonDeserializer.java

@Override
public T deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
    try {/*from w  ww .  j a  v  a 2 s  . com*/
        return jsonMapper.fromJson(jp.readValueAsTree().toString(), type);
    } catch (JsonException e) {
        throw new JsonMappingException(e.getMessage(), jp.getCurrentLocation(), e.getCause());
    }
}

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;
                }//  w  w  w .j a va 2  s  .  c o  m
                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;
}

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;
                    }/* www  .  ja va2s.  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:io.fabric8.maven.core.util.KubernetesResourceUtil.java

private static Map<String, Object> readFragment(File file, String ext) throws IOException {
    ObjectMapper mapper = new ObjectMapper("json".equals(ext) ? new JsonFactory() : new YAMLFactory());
    TypeReference<HashMap<String, Object>> typeRef = new TypeReference<HashMap<String, Object>>() {
    };/*from  ww w .  j a va 2 s . c om*/
    try {
        Map<String, Object> ret = mapper.readValue(file, typeRef);
        return ret != null ? ret : new HashMap<String, Object>();
    } catch (JsonProcessingException e) {
        throw new JsonMappingException(String.format("[%s] %s", file, e.getMessage()), e.getLocation(), e);
    }
}