use of 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"))))));
}
use of com.fasterxml.jackson.databind.ObjectReader in project hadoop by apache.
the class TestJsonUtil method testToXAttrMap.
@Test
public void testToXAttrMap() 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);
XAttr xAttr1 = (new XAttr.Builder()).setNameSpace(XAttr.NameSpace.USER).setName("a1").setValue(XAttrCodec.decodeValue("0x313233")).build();
XAttr xAttr2 = (new XAttr.Builder()).setNameSpace(XAttr.NameSpace.USER).setName("a2").setValue(XAttrCodec.decodeValue("0x313131")).build();
List<XAttr> xAttrs = Lists.newArrayList();
xAttrs.add(xAttr1);
xAttrs.add(xAttr2);
Map<String, byte[]> xAttrMap = XAttrHelper.buildXAttrMap(xAttrs);
Map<String, byte[]> parsedXAttrMap = JsonUtilClient.toXAttrs(json);
Assert.assertEquals(xAttrMap.size(), parsedXAttrMap.size());
Iterator<Entry<String, byte[]>> iter = xAttrMap.entrySet().iterator();
while (iter.hasNext()) {
Entry<String, byte[]> entry = iter.next();
Assert.assertArrayEquals(entry.getValue(), parsedXAttrMap.get(entry.getKey()));
}
}
use of com.fasterxml.jackson.databind.ObjectReader in project hadoop by apache.
the class TestJsonUtil method testHdfsFileStatus.
@Test
public void testHdfsFileStatus() throws IOException {
final long now = Time.now();
final String parent = "/dir";
final HdfsFileStatus status = new HdfsFileStatus(1001L, false, 3, 1L << 26, now, now + 10, new FsPermission((short) 0644), "user", "group", DFSUtil.string2Bytes("bar"), DFSUtil.string2Bytes("foo"), HdfsConstants.GRANDFATHER_INODE_ID, 0, null, (byte) 0, null);
final FileStatus fstatus = toFileStatus(status, parent);
System.out.println("status = " + status);
System.out.println("fstatus = " + fstatus);
final String json = JsonUtil.toJsonString(status, true);
System.out.println("json = " + json.replace(",", ",\n "));
ObjectReader reader = new ObjectMapper().readerFor(Map.class);
final HdfsFileStatus s2 = JsonUtilClient.toFileStatus((Map<?, ?>) reader.readValue(json), true);
final FileStatus fs2 = toFileStatus(s2, parent);
System.out.println("s2 = " + s2);
System.out.println("fs2 = " + fs2);
Assert.assertEquals(fstatus, fs2);
}
use of com.fasterxml.jackson.databind.ObjectReader in project hadoop by apache.
the class TestJsonUtil method testToAclStatus.
@Test
public void testToAclStatus() throws IOException {
String jsonString = "{\"AclStatus\":{\"entries\":[\"user::rwx\",\"user:user1:rw-\",\"group::rw-\",\"other::r-x\"],\"group\":\"supergroup\",\"owner\":\"testuser\",\"stickyBit\":false}}";
ObjectReader reader = new ObjectMapper().readerFor(Map.class);
Map<?, ?> json = reader.readValue(jsonString);
List<AclEntry> aclSpec = Lists.newArrayList(aclEntry(ACCESS, USER, ALL), aclEntry(ACCESS, USER, "user1", READ_WRITE), aclEntry(ACCESS, GROUP, READ_WRITE), aclEntry(ACCESS, OTHER, READ_EXECUTE));
AclStatus.Builder aclStatusBuilder = new AclStatus.Builder();
aclStatusBuilder.owner("testuser");
aclStatusBuilder.group("supergroup");
aclStatusBuilder.addEntries(aclSpec);
aclStatusBuilder.stickyBit(false);
Assert.assertEquals("Should be equal", aclStatusBuilder.build(), JsonUtilClient.toAclStatus(json));
}
use of com.fasterxml.jackson.databind.ObjectReader in project Fast-Android-Networking by amitshekhariitbhu.
the class JacksonParserFactory method responseBodyParser.
@Override
public Parser<ResponseBody, ?> responseBodyParser(Type type) {
JavaType javaType = mapper.getTypeFactory().constructType(type);
ObjectReader reader = mapper.readerFor(javaType);
return new JacksonResponseBodyParser<>(reader);
}
Aggregations