Search in sources :

Example 6 with JsonMappingException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonMappingException in project OpenClinica by OpenClinica.

the class XformMetaDataService method executeIndividualCrf.

public void executeIndividualCrf(ExecuteIndividualCrfObject eicObject) {
    for (OCodmComplexTypeDefinitionFormLayoutDef formLayoutDef : eicObject.formLayoutDefs) {
        List<String> fileLinks = null;
        String vForm = "";
        RestTemplate rest = new RestTemplate();
        if (eicObject.form != null) {
            List<FormVersion> versions = eicObject.form.getVersions();
            for (FormVersion version : versions) {
                if (version.getName().equals(formLayoutDef.getOID())) {
                    fileLinks = version.getFileLinks();
                    for (String fileLink : fileLinks) {
                        if (fileLink.endsWith(VERSION)) {
                            vForm = rest.getForObject(fileLink, String.class);
                            break;
                        }
                    }
                    if (!eicObject.errors.hasErrors()) {
                        ObjectMapper mapper = new ObjectMapper();
                        TypeReference<List<XformGroup>> mapType = new TypeReference<List<XformGroup>>() {
                        };
                        List<XformGroup> jsonList = null;
                        try {
                            jsonList = mapper.readValue(vForm, mapType);
                        } catch (JsonParseException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        } catch (JsonMappingException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                        XformContainer xformContainer = new XformContainer();
                        xformContainer.setGroups(jsonList);
                        eicObject.setContainer(xformContainer);
                        if (eicObject.errors.hasErrors()) {
                            return;
                        }
                        // Save meta-data in database
                        saveFormMetadata(eicObject, version, eicObject.container, formLayoutDef, fileLinks);
                    }
                }
            }
        }
    }
}
Also used : OCodmComplexTypeDefinitionFormLayoutDef(org.openclinica.ns.odm_ext_v130.v31.OCodmComplexTypeDefinitionFormLayoutDef) XformGroup(org.akaza.openclinica.domain.xform.XformGroup) IOException(java.io.IOException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) XformContainer(org.akaza.openclinica.domain.xform.XformContainer) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) RestTemplate(org.springframework.web.client.RestTemplate) List(java.util.List) ArrayList(java.util.ArrayList) TypeReference(com.fasterxml.jackson.core.type.TypeReference) FormVersion(org.akaza.openclinica.service.dto.FormVersion) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 7 with JsonMappingException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonMappingException in project jackson-databind by FasterXML.

the class TestInferredMutators method testFinalFieldIgnoral.

/*
    /**********************************************************
    /* Unit tests
    /**********************************************************
     */
// for #190
public void testFinalFieldIgnoral() throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    // default value is 'enabled', for backwards compatibility
    assertTrue(mapper.isEnabled(MapperFeature.ALLOW_FINAL_FIELDS_AS_MUTATORS));
    mapper.disable(MapperFeature.ALLOW_FINAL_FIELDS_AS_MUTATORS);
    try {
        /*p =*/
        mapper.readValue("{\"x\":2}", FixedPoint.class);
        fail("Should not try to use final field");
    } catch (JsonMappingException e) {
        verifyException(e, "unrecognized field \"x\"");
    }
}
Also used : JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 8 with JsonMappingException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonMappingException in project jackson-databind by FasterXML.

the class TestSubtypes method testErrorMessage.

public void testErrorMessage() throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    try {
        mapper.readValue("{ \"type\": \"z\"}", BaseX.class);
        fail("Should have failed");
    } catch (JsonMappingException e) {
        verifyException(e, "known type ids =");
    }
}
Also used : JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 9 with JsonMappingException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonMappingException in project jackson-databind by FasterXML.

the class ClassUtil method throwAsMappingException.

/**
     * @since 2.9
     */
public static <T> T throwAsMappingException(DeserializationContext ctxt, IOException e0) throws JsonMappingException {
    if (e0 instanceof JsonMappingException) {
        throw (JsonMappingException) e0;
    }
    JsonMappingException e = JsonMappingException.from(ctxt, e0.getMessage());
    e.initCause(e0);
    throw e;
}
Also used : JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException)

Example 10 with JsonMappingException

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonMappingException in project jackson-databind by FasterXML.

the class FromStringDeserializer method deserialize.

/*
    /**********************************************************
    /* Deserializer implementations
    /**********************************************************
     */
@SuppressWarnings("unchecked")
@Override
public T deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
    // 22-Sep-2012, tatu: For 2.1, use this new method, may force coercion:
    String text = p.getValueAsString();
    if (text != null) {
        // has String representation
        if (text.length() == 0 || (text = text.trim()).length() == 0) {
            // 04-Feb-2013, tatu: Usually should become null; but not always
            return _deserializeFromEmptyString();
        }
        Exception cause = null;
        try {
            T result = _deserialize(text, ctxt);
            if (result != null) {
                return result;
            }
        } catch (IllegalArgumentException iae) {
            cause = iae;
        } catch (MalformedURLException me) {
            cause = me;
        }
        String msg = "not a valid textual representation";
        if (cause != null) {
            String m2 = cause.getMessage();
            if (m2 != null) {
                msg = msg + ", problem: " + m2;
            }
        }
        // 05-May-2016, tatu: Unlike most usage, this seems legit, so...
        JsonMappingException e = ctxt.weirdStringException(text, _valueClass, msg);
        if (cause != null) {
            e.initCause(cause);
        }
        throw e;
    // nothing to do here, yet? We'll fail anyway
    }
    JsonToken t = p.getCurrentToken();
    // [databind#381]
    if (t == JsonToken.START_ARRAY && ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
        p.nextToken();
        final T value = deserialize(p, ctxt);
        if (p.nextToken() != JsonToken.END_ARRAY) {
            handleMissingEndArrayForSingle(p, ctxt);
        }
        return value;
    }
    if (t == JsonToken.VALUE_EMBEDDED_OBJECT) {
        // Trivial cases; null to null, instance of type itself returned as is
        Object ob = p.getEmbeddedObject();
        if (ob == null) {
            return null;
        }
        if (_valueClass.isAssignableFrom(ob.getClass())) {
            return (T) ob;
        }
        return _deserializeEmbedded(ob, ctxt);
    }
    return (T) ctxt.handleUnexpectedToken(_valueClass, p);
}
Also used : MalformedURLException(java.net.MalformedURLException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) InvalidFormatException(com.fasterxml.jackson.databind.exc.InvalidFormatException) MalformedURLException(java.net.MalformedURLException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException)

Aggregations

JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)185 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)93 IOException (java.io.IOException)80 JsonParseException (com.fasterxml.jackson.core.JsonParseException)57 Test (org.junit.Test)45 ATTest (org.jboss.eap.additional.testsuite.annotations.ATTest)33 JsonGenerationException (com.fasterxml.jackson.core.JsonGenerationException)24 ArrayList (java.util.ArrayList)16 Map (java.util.Map)16 JsonNode (com.fasterxml.jackson.databind.JsonNode)15 File (java.io.File)15 HashMap (java.util.HashMap)15 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)13 InputStream (java.io.InputStream)11 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)10 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 List (java.util.List)8 Writer (org.alfresco.rest.framework.jacksonextensions.JacksonHelper.Writer)7 Test (org.junit.jupiter.api.Test)6