Search in sources :

Example 51 with ObjectReader

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectReader in project camel by apache.

the class SObjectTreeResponseTest method shouldDeserializeJsonFromSalesforceFailureExample.

@Test
public void shouldDeserializeJsonFromSalesforceFailureExample() throws Exception {
    final String json = //
    "{\n" + //
    "   \"hasErrors\" : true,\n" + //
    "   \"results\" : [{\n" + //
    "     \"referenceId\" : \"ref2\",\n" + //
    "     \"errors\" : [{\n" + //
    "       \"statusCode\" : \"INVALID_EMAIL_ADDRESS\",\n" + //
    "       \"message\" : \"Email: invalid email address: 123\",\n" + //
    "       \"fields\" : [ \"Email\" ]\n" + //
    "       }]\n" + //
    "     }]\n" + "}";
    final ObjectMapper mapper = new ObjectMapper();
    final ObjectReader reader = mapper.readerFor(SObjectTreeResponse.class);
    final SObjectTreeResponse response = reader.readValue(json);
    assertNotNull("Response should be parsed", response);
    assertTrue("`hasErrors` flag should be true", response.hasErrors());
    assertEquals("Should read one reference", 1, response.getResults().size());
    assertThat("The reference should be read as expected", response.getResults(), hasItems(new ReferenceId("ref2", null, Arrays.asList(new RestError("INVALID_EMAIL_ADDRESS", "Email: invalid email address: 123", Arrays.asList("Email"))))));
}
Also used : RestError(org.apache.camel.component.salesforce.api.dto.RestError) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 52 with ObjectReader

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectReader in project midpoint by Evolveum.

the class JsonValueParser method asDomElement.

Element asDomElement() throws IOException {
    ObjectMapper mapper = (ObjectMapper) parser.getCodec();
    ObjectReader r = mapper.readerFor(Document.class);
    return ((Document) r.readValue(node)).getDocumentElement();
}
Also used : ObjectReader(com.fasterxml.jackson.databind.ObjectReader) Document(org.w3c.dom.Document) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 53 with ObjectReader

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectReader in project midpoint by Evolveum.

the class JsonValueParser method parse.

@Override
public T parse(QName typeName, XNodeProcessorEvaluationMode mode) throws SchemaException {
    ObjectMapper mapper = (ObjectMapper) parser.getCodec();
    Class clazz = XsdTypeMapper.toJavaType(typeName);
    ObjectReader r = mapper.readerFor(clazz);
    try {
        return r.readValue(node);
    // TODO implement COMPAT mode
    } catch (IOException e) {
        throw new SchemaException("Cannot parse value: " + e.getMessage(), e);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 54 with ObjectReader

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectReader in project JMRI by JMRI.

the class JsonServer method handleClient.

// Handle communication to a client through inStream and outStream
@Override
public void handleClient(DataInputStream inStream, DataOutputStream outStream) throws IOException {
    ObjectReader reader = this.mapper.reader();
    JsonClientHandler handler = new JsonClientHandler(new JsonConnection(outStream));
    // Start by sending a welcome message
    handler.onMessage(JsonClientHandler.HELLO_MSG);
    while (true) {
        try {
            handler.onMessage(reader.readTree((InputStream) inStream));
        // Read the command from the client
        } catch (IOException e) {
            // attempt to close the connection and throw the exception
            handler.dispose();
            throw e;
        } catch (NoSuchElementException nse) {
            // so break out of the loop
            break;
        }
    }
    handler.dispose();
}
Also used : JsonClientHandler(jmri.server.json.JsonClientHandler) DataInputStream(java.io.DataInputStream) InputStream(java.io.InputStream) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) IOException(java.io.IOException) JsonConnection(jmri.server.json.JsonConnection) NoSuchElementException(java.util.NoSuchElementException)

Example 55 with ObjectReader

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectReader in project logging-log4j2 by apache.

the class LevelMixInTest method testContainer.

@Test
public void testContainer() throws IOException {
    final Fixture expected = new Fixture();
    final String str = writer.writeValueAsString(expected);
    Assert.assertTrue(str.contains("DEBUG"));
    final ObjectReader fixtureReader = log4jObjectMapper.readerFor(Fixture.class);
    final Fixture actual = fixtureReader.readValue(str);
    Assert.assertEquals(expected, actual);
}
Also used : ObjectReader(com.fasterxml.jackson.databind.ObjectReader) Test(org.junit.Test)

Aggregations

ObjectReader (com.fasterxml.jackson.databind.ObjectReader)82 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)33 IOException (java.io.IOException)32 Test (org.junit.Test)23 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)12 JsonNode (com.fasterxml.jackson.databind.JsonNode)9 ArrayList (java.util.ArrayList)8 JavaType (com.fasterxml.jackson.databind.JavaType)7 InputStream (java.io.InputStream)7 HashMap (java.util.HashMap)6 CsvSchema (com.fasterxml.jackson.dataformat.csv.CsvSchema)5 Map (java.util.Map)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)4 CsvMapper (com.fasterxml.jackson.dataformat.csv.CsvMapper)4 PluginTestVerifier (com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier)4 Method (java.lang.reflect.Method)4 List (java.util.List)4 DeserializationFeature (com.fasterxml.jackson.databind.DeserializationFeature)3 MappingIterator (com.fasterxml.jackson.databind.MappingIterator)3 JSONLayoutPage (org.knime.js.core.layout.bs.JSONLayoutPage)3