static String generateAndParse(ProtobufJSON json) throws Exception { StringWriter sw = new StringWriter(); json.writeTo(sw, person); String generated = sw.toString(); JsonParser parser = json.getJsonFactory().createJsonParser(generated); Person parsedPerson = json.parseFrom(parser, Person.class); parser.close(); assertEquals(person, parsedPerson); return generated; }
static String generatedAndParse( ProtobufJSON json, List<Person> personList, List<Person> parsedPersonList) throws Exception { StringWriter sw = new StringWriter(); json.writeTo(sw, personList, Person.class); String generated = sw.toString(); JsonParser parser = json.getJsonFactory().createJsonParser(generated); json.appendMessageFrom(parser, parsedPersonList, Person.class); parser.close(); assertTrue(personList.size() == parsedPersonList.size()); for (int i = 0, len = personList.size(); i < len; i++) assertEquals(personList.get(i), parsedPersonList.get(i)); return generated; }