### Question:
User { public static String toJson(Collection<User> users) throws IOException { StringWriter sw = new StringWriter(); JsonFactory f = new JsonFactory(); JsonGenerator g = f.createJsonGenerator(sw); g.writeStartObject(); g.writeFieldName("users"); g.writeStartArray(); for (User user : users) { user.write(g); } g.writeEndArray(); g.writeEndObject(); g.close(); String json = sw.toString(); return json; } User(); static String toJson(Collection<User> users); String getId(); void setId(String id); String getRole(); void setRole(String role); String getUsername(); void setUsername(String username); String getPassword(); void setPassword(String password); String getToken(); void setToken(String token); Map<String, String> getAttributes(); void fromJson(String json); String toJson();  }### Answer:
@Test public void testToJson() { try { User user = new User(); user.fromJson(this.json); String gen = user.toJson(); User reparsed = new User(); reparsed.fromJson(gen); assertEquals(user.getUsername(), reparsed.getUsername()); assertTrue(reparsed.getAttributes().containsKey("email")); assertEquals("12/29/1981", reparsed.getAttributes().get("dob")); } catch (IOException e) { fail(e.toString()); } catch (URISyntaxException e) { fail(e.toString()); } catch (Exception e) { fail(e.toString()); } }