Services { @Override public String toString() { return "Services{" + "environment='" + environment + '\'' + ", services=" + services + '}'; } Services(String environment, Set<Service> services); @JsonProperty String getEnvironment(); @JsonProperty Set<Service> getServices(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }
@Test public void testToJson() throws IOException { Service blue = new Service(Id.<Service>valueOf("c0c5be5f-b298-4cfa-922a-3e5954208444"), Id.<Node>valueOf("3ff52f57-04e0-46c3-b606-7497b09dd5c7"), "blue", "poolA", "/locationA", ImmutableMap.of("key", "valueA")); Service red = new Service(Id.<Service>valueOf("e3780aba-98fe-4de1-b682-5cd7a3264367"), Id.<Node>valueOf("989c4a90-ef68-4a05-8ad9-73a02aea406c"), "red", "poolB", "/locationB", ImmutableMap.of("key", "valueB")); Services services = new Services("testing", ImmutableSet.of(blue, red)); String json = jsonCodec(Services.class).toJson(services); JsonCodec<Object> codec = jsonCodec(Object.class); Object parsed = codec.fromJson(json); Object expected = codec.fromJson(Resources.toString(Resources.getResource("services.json"), Charsets.UTF_8)); assertEquals(parsed, expected); }