Exemplo n.º 1
0
 // Test for [JACKSON-554]
 public void testTreeToValue() throws Exception {
   String JSON = "{\"leaf\":{\"value\":13}}";
   ObjectMapper mapper = new ObjectMapper();
   mapper.addMixInAnnotations(Leaf.class, LeafMixIn.class);
   JsonNode root = mapper.readTree(JSON);
   // Ok, try converting to bean using two mechanisms
   Root r1 = mapper.treeToValue(root, Root.class);
   assertNotNull(r1);
   assertEquals(13, r1.leaf.value);
 }
Exemplo n.º 2
0
  /**
   * Simple test to verify that byte[] values can be handled properly when converting, as long as
   * there is metadata (from POJO definitions).
   */
  public void testIssue709() throws Exception {
    byte[] inputData = new byte[] {1, 2, 3};
    ObjectNode node = MAPPER.createObjectNode();
    node.put("data", inputData);
    Issue709Bean result = MAPPER.treeToValue(node, Issue709Bean.class);
    String json = MAPPER.writeValueAsString(node);
    Issue709Bean resultFromString = MAPPER.readValue(json, Issue709Bean.class);
    Issue709Bean resultFromConvert = MAPPER.convertValue(node, Issue709Bean.class);

    // all methods should work equally well:
    Assert.assertArrayEquals(inputData, resultFromString.data);
    Assert.assertArrayEquals(inputData, resultFromConvert.data);
    Assert.assertArrayEquals(inputData, result.data);
  }