use of org.apache.flink.shaded.jackson2.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 org.apache.flink.shaded.jackson2.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 org.apache.flink.shaded.jackson2.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 org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectReader in project hadoop by apache.
the class JsonUtilClient method toXAttrNames.
static List<String> toXAttrNames(final Map<?, ?> json) throws IOException {
if (json == null) {
return null;
}
final String namesInJson = (String) json.get("XAttrNames");
ObjectReader reader = new ObjectMapper().readerFor(List.class);
final List<Object> xattrs = reader.readValue(namesInJson);
final List<String> names = Lists.newArrayListWithCapacity(json.keySet().size());
for (Object xattr : xattrs) {
names.add((String) xattr);
}
return names;
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectReader in project camel by apache.
the class SObjectTreeResponseTest method shouldDeserializeJsonFromSalesforceExample.
@Test
public void shouldDeserializeJsonFromSalesforceExample() throws Exception {
final String json = //
"{\n" + //
" \"hasErrors\" : false,\n" + //
" \"results\" : [{\n" + //
" \"referenceId\" : \"ref1\",\n" + //
" \"id\" : \"001D000000K0fXOIAZ\"\n" + //
" },{\n" + //
" \"referenceId\" : \"ref4\",\n" + //
" \"id\" : \"001D000000K0fXPIAZ\"\n" + //
" },{\n" + //
" \"referenceId\" : \"ref2\",\n" + //
" \"id\" : \"003D000000QV9n2IAD\"\n" + //
" },{\n" + //
" \"referenceId\" : \"ref3\",\n" + //
" \"id\" : \"003D000000QV9n3IAD\"\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);
assertFalse("`hasErrors` flag should be false", response.hasErrors());
assertEquals("Should read 4 references", 4, response.getResults().size());
assertThat("4 references should be read as expected", response.getResults(), hasItems(//
new ReferenceId("ref1", "001D000000K0fXOIAZ", Collections.emptyList()), //
new ReferenceId("ref4", "001D000000K0fXPIAZ", Collections.emptyList()), //
new ReferenceId("ref2", "003D000000QV9n2IAD", Collections.emptyList()), new ReferenceId("ref3", "003D000000QV9n3IAD", Collections.emptyList())));
}
Aggregations