@SuppressWarnings("unchecked") public T parse(JsonParser jsonParser) throws IOException { ParseHandler<T> parseHandler = Acela.getTranslator(getType()); T translator = parseHandler.getInstance(); parse(translator, jsonParser); return translator; }
@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); }
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(); }
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(); }