Пример #1
0
 private void _doTestUntyped(final Map<String, ObjectWrapper> map) {
   assertEquals(Double.valueOf(42), map.get("double").getObject());
   assertEquals("string", map.get("string").getObject());
   assertEquals(Boolean.TRUE, map.get("boolean").getObject());
   assertEquals(Collections.singletonList("list0"), map.get("list").getObject());
   assertTrue(map.containsKey("null"));
   assertNull(map.get("null"));
   assertEquals(5, map.size());
 }
  private Object success(Class<?> clazz, HttpInputMessage inputMessage)
      throws JsonParseException, IOException {

    // Note, parsing code used from ektorp project
    JsonParser jp = objectMapper.getJsonFactory().createJsonParser(inputMessage.getBody());
    if (jp.nextToken() != JsonToken.START_OBJECT) {
      throw new RuntimeException("Expected data to start with an Object");
    }
    Map<String, Integer> fields = readHeaderFields(jp);

    List result;
    if (fields.containsKey(TOTAL_ROWS_FIELD_NAME)) {
      int totalRows = fields.get(TOTAL_ROWS_FIELD_NAME);
      if (totalRows == 0) {
        return Collections.emptyList();
      }
      result = new ArrayList(totalRows);
    } else {
      result = new ArrayList();
    }

    ParseState state = new ParseState();

    Object first = parseFirstRow(jp, state, clazz);
    if (first == null) {
      return Collections.emptyList();
    } else {
      result.add(first);
    }

    while (jp.getCurrentToken() != null) {
      skipToField(jp, state.docFieldName, state);
      if (atEndOfRows(jp)) {
        return result;
      }
      result.add(jp.readValueAs(clazz));
      endRow(jp, state);
    }
    return result;
  }