Search in sources :

Example 1 with ObjectReader

use of com.fasterxml.jackson.databind.ObjectReader in project hadoop by apache.

the class TestJsonUtil method testGetXAttrFromJson.

@Test
public void testGetXAttrFromJson() throws IOException {
    String jsonString = "{\"XAttrs\":[{\"name\":\"user.a1\",\"value\":\"0x313233\"}," + "{\"name\":\"user.a2\",\"value\":\"0x313131\"}]}";
    ObjectReader reader = new ObjectMapper().readerFor(Map.class);
    Map<?, ?> json = reader.readValue(jsonString);
    // Get xattr: user.a2
    byte[] value = JsonUtilClient.getXAttr(json, "user.a2");
    Assert.assertArrayEquals(XAttrCodec.decodeValue("0x313131"), value);
}
Also used : ObjectReader(com.fasterxml.jackson.databind.ObjectReader) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 2 with ObjectReader

use of com.fasterxml.jackson.databind.ObjectReader in project dropwizard by dropwizard.

the class ParanamerModuleTest method deserializePersonWithoutAnnotations.

@Test
public void deserializePersonWithoutAnnotations() throws IOException {
    final ObjectReader reader = mapper.readerFor(Person.class);
    final Person person = reader.readValue("{ \"name\": \"Foo\", \"surname\": \"Bar\" }");
    assertThat(person.getName()).isEqualTo("Foo");
    assertThat(person.getSurname()).isEqualTo("Bar");
}
Also used : ObjectReader(com.fasterxml.jackson.databind.ObjectReader) Test(org.junit.Test)

Example 3 with ObjectReader

use of com.fasterxml.jackson.databind.ObjectReader in project native-navigation by airbnb.

the class ConversionUtil method toType.

/** Converts the provided {@code readableMap} into an object of the provided {@code targetType} */
static <T> T toType(ObjectMapper objectMapper, ReadableMap readableMap, Class<T> targetType) {
    ObjectNode jsonNode = toJsonObject(readableMap);
    ObjectReader objectReader = JacksonUtils.readerForType(objectMapper, targetType);
    //noinspection OverlyBroadCatchBlock
    try {
        return objectReader.readValue(jsonNode);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) IOException(java.io.IOException)

Example 4 with ObjectReader

use of com.fasterxml.jackson.databind.ObjectReader in project pinpoint by naver.

the class ObjectReaderIT method testReadValue.

@Test
public void testReadValue() throws Exception {
    String json_str = "{\"name\" : \"Jackson\"}";
    byte[] json_b = json_str.getBytes("UTF-8");
    ObjectReader reader = mapper.reader(__POJO.class);
    __POJO pojo = reader.readValue(json_str);
    pojo = reader.readValue(json_b);
    PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
    verifier.printCache();
    Method readval1 = ObjectReader.class.getMethod("readValue", String.class);
    Method readval2 = ObjectReader.class.getMethod("readValue", byte[].class);
    verifier.verifyTrace(event("JACKSON", readval1, Expectations.annotation("jackson.json.length", json_str.length())));
    verifier.verifyTrace(event("JACKSON", readval2, Expectations.annotation("jackson.json.length", json_b.length)));
    verifier.verifyTraceCount(0);
}
Also used : ObjectReader(com.fasterxml.jackson.databind.ObjectReader) Method(java.lang.reflect.Method) PluginTestVerifier(com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier) Test(org.junit.Test)

Example 5 with ObjectReader

use of com.fasterxml.jackson.databind.ObjectReader in project camel by apache.

the class RestErrorTest method shouldDeserializeFromJson.

@Test
public void shouldDeserializeFromJson() throws Exception {
    final ObjectMapper objectMapper = new ObjectMapper();
    final ObjectReader reader = objectMapper.readerFor(RestError.class);
    final RestError gotWithErrorCode = reader.<RestError>readValue("{\"errorCode\":\"errorCode\",\"message\":\"message\",\"fields\":[ \"field1\",\"field2\" ]}");
    assertEquals(gotWithErrorCode, error);
    final RestError gotWithStatusCode = reader.<RestError>readValue("{\"statusCode\":\"errorCode\",\"message\":\"message\",\"fields\":[ \"field1\",\"field2\" ]}");
    assertEquals(gotWithStatusCode, error);
}
Also used : ObjectReader(com.fasterxml.jackson.databind.ObjectReader) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

ObjectReader (com.fasterxml.jackson.databind.ObjectReader)32 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)13 Test (org.junit.Test)12 IOException (java.io.IOException)6 JavaType (com.fasterxml.jackson.databind.JavaType)5 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)4 PluginTestVerifier (com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier)2 Method (java.lang.reflect.Method)2 NoSuchElementException (java.util.NoSuchElementException)2 AclEntry (org.apache.hadoop.fs.permission.AclEntry)2 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 InvalidFormatException (com.fasterxml.jackson.databind.exc.InvalidFormatException)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 FilterProvider (com.fasterxml.jackson.databind.ser.FilterProvider)1 SimpleFilterProvider (com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider)1 AvroFactory (com.fasterxml.jackson.dataformat.avro.AvroFactory)1 AvroSchema (com.fasterxml.jackson.dataformat.avro.AvroSchema)1