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);
}
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");
}
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);
}
}
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);
}
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);
}
Aggregations