Ejemplo n.º 1
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);
  }
Ejemplo n.º 2
0
 public static <T> T convertValue(Object value, Class<T> type) {
   return OBJECT_MAPPER.convertValue(value, type);
 }
Ejemplo n.º 3
0
 // Return given object as a list
 // AG
 static List<?> getListFromObject(Object o) {
   @SuppressWarnings("rawtypes")
   List<?> temp = new LinkedList();
   if (o instanceof List<?>) temp = mapper.convertValue(o, List.class);
   return temp;
 }
Ejemplo n.º 4
0
 // Return given object as a String
 // AG
 static String getStringFromObject(Object o) {
   String temp = "";
   if (o instanceof String) temp = mapper.convertValue(o, String.class);
   return temp;
 }
Ejemplo n.º 5
0
 // Return given object as a double
 // AG
 static double getDoubleFromObject(Object o) {
   double temp = 0.0;
   if (o instanceof Double) temp = mapper.convertValue(o, Double.class);
   return temp;
 }
Ejemplo n.º 6
0
 // Return given object as an int
 // AG
 static int getIntFromObject(Object o) {
   int temp = 0;
   if (o instanceof Integer) temp = mapper.convertValue(o, Integer.class);
   return temp;
 }