Search in sources :

Example 46 with ObjectReader

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()));
    }
}
Also used : Entry(java.util.Map.Entry) AclEntry(org.apache.hadoop.fs.permission.AclEntry) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) XAttr(org.apache.hadoop.fs.XAttr) Test(org.junit.Test)

Example 47 with ObjectReader

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);
}
Also used : FileStatus(org.apache.hadoop.fs.FileStatus) HdfsFileStatus(org.apache.hadoop.hdfs.protocol.HdfsFileStatus) HdfsFileStatus(org.apache.hadoop.hdfs.protocol.HdfsFileStatus) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) FsPermission(org.apache.hadoop.fs.permission.FsPermission) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 48 with ObjectReader

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));
}
Also used : AclStatus(org.apache.hadoop.fs.permission.AclStatus) AclEntry(org.apache.hadoop.fs.permission.AclEntry) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 49 with ObjectReader

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;
}
Also used : ObjectReader(com.fasterxml.jackson.databind.ObjectReader) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 50 with ObjectReader

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())));
}
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)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