Search in sources :

Example 16 with ObjectReader

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"))))));
}
Also used : RestError(org.apache.camel.component.salesforce.api.dto.RestError) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 17 with ObjectReader

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

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);
}
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 19 with ObjectReader

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));
}
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 20 with ObjectReader

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

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