Exemplo n.º 1
0
 @SuppressWarnings("unchecked")
 public T parse(JsonParser jsonParser) throws IOException {
   ParseHandler<T> parseHandler = Acela.getTranslator(getType());
   T translator = parseHandler.getInstance();
   parse(translator, jsonParser);
   return translator;
 }
Exemplo n.º 2
0
  @Test
  public void testListParse() throws IOException {

    StringWriter stringWriter = new StringWriter();
    JsonGenerator jsonGenerator = Acela.JSON_FACTORY.createGenerator(stringWriter);

    TestingUtils.writeTestArray(jsonGenerator, null);

    jsonGenerator.close();

    List<SimpleObject> simpleObjects =
        Acela.getTranslator(SimpleObject.class).parseList(stringWriter.toString());
    assertNotNull(simpleObjects);
    assertEquals(2, simpleObjects.size());

    String generatedString = Acela.getTranslator(SimpleObject.class).serializeList(simpleObjects);
    String jsonString = stringWriter.toString();
    assertEquals(jsonString, generatedString);
  }
Exemplo n.º 3
0
  public void serializeArray(JsonGenerator jsonGenerator, T[] translatorTypes) throws IOException {
    jsonGenerator.writeStartArray();
    for (T type : translatorTypes) {
      if (type != null) {
        Acela.getTranslator(getType()).serialize(type, jsonGenerator);
      } else {
        jsonGenerator.writeNull();
      }
    }

    jsonGenerator.writeEndArray();
  }
Exemplo n.º 4
0
  public void serializeMap(JsonGenerator jsonGenerator, Map<String, T> map) throws IOException {
    jsonGenerator.writeStartObject();
    for (Map.Entry<String, T> entry : map.entrySet()) {
      jsonGenerator.writeFieldName(entry.getKey());
      if (entry.getValue() == null) {
        jsonGenerator.writeNull();
      } else {
        Acela.getTranslator(getType()).serialize(entry.getValue(), jsonGenerator);
      }
    }

    jsonGenerator.writeEndObject();
  }