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

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

Introduction

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

Prototype

public void prependPath(Reference paramReference) 

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   ww  w.  j  a  v a2 s . com
                } 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  a  v a2s  .  c  om*/
                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.github.shyiko.jackson.module.advice.AdvisedBeanSerializer.java

protected void serializeFields(Object bean, JsonGenerator jgen, SerializerProvider provider)
        throws IOException {
    final BeanPropertyWriter[] props;
    if (_filteredProps != null && provider.getActiveView() != null) {
        props = _filteredProps;/*from   w  w  w . j  a va2s.  com*/
    } else {
        props = _props;
    }
    int i = 0;
    try {
        for (final int len = props.length; i < len; ++i) {
            BeanPropertyWriter prop = props[i];
            if (prop != null) { // can have nulls in filtered list
                if (!beanSerializerAdvice.intercept(bean, jgen, prop, provider)) {
                    beanSerializerAdvice.before(bean, jgen, prop, provider);
                    prop.serializeAsField(bean, jgen, provider);
                    beanSerializerAdvice.after(bean, jgen, prop, provider);
                }
            }
        }
        if (_anyGetterWriter != null) {
            _anyGetterWriter.getAndSerialize(bean, jgen, provider);
        }
    } catch (Exception e) {
        String name = (i == props.length) ? "[anySetter]" : props[i].getName();
        wrapAndThrow(provider, e, bean, name);
    } catch (StackOverflowError e) {
        /* 04-Sep-2009, tatu: Dealing with this is tricky, since we do not
         *   have many stack frames to spare... just one or two; can't
         *   make many calls.
         */
        JsonMappingException mapE = new JsonMappingException("Infinite recursion (StackOverflowError)", e);
        String name = (i == props.length) ? "[anySetter]" : props[i].getName();
        mapE.prependPath(new JsonMappingException.Reference(bean, name));
        throw mapE;
    }
}

From source file:com.github.shyiko.jackson.module.advice.AdvisedBeanSerializer.java

protected void serializeFieldsFiltered(Object bean, JsonGenerator jgen, SerializerProvider provider)
        throws IOException {
    /* note: almost verbatim copy of "serializeFields"; copied (instead of merged)
     * so that old method need not add check for existence of filter.
     *//*from  w ww .j a  v a  2s  . c  o m*/

    final BeanPropertyWriter[] props;
    if (_filteredProps != null && provider.getActiveView() != null) {
        props = _filteredProps;
    } else {
        props = _props;
    }
    final PropertyFilter filter = findPropertyFilter(provider, _propertyFilterId, bean);
    // better also allow missing filter actually..
    if (filter == null) {
        serializeFields(bean, jgen, provider);
        return;
    }
    int i = 0;
    try {
        for (final int len = props.length; i < len; ++i) {
            BeanPropertyWriter prop = props[i];
            if (prop != null) { // can have nulls in filtered list
                if (!beanSerializerAdvice.intercept(bean, jgen, prop, provider)) {
                    beanSerializerAdvice.before(bean, jgen, prop, provider);
                    filter.serializeAsField(bean, jgen, provider, prop);
                    beanSerializerAdvice.after(bean, jgen, prop, provider);
                }
            }
        }
        if (_anyGetterWriter != null) {
            _anyGetterWriter.getAndFilter(bean, jgen, provider, filter);
        }
    } catch (Exception e) {
        String name = (i == props.length) ? "[anySetter]" : props[i].getName();
        wrapAndThrow(provider, e, bean, name);
    } catch (StackOverflowError e) {
        JsonMappingException mapE = new JsonMappingException("Infinite recursion (StackOverflowError)", e);
        String name = (i == props.length) ? "[anySetter]" : props[i].getName();
        mapE.prependPath(new JsonMappingException.Reference(bean, name));
        throw mapE;
    }
}