Service { @Override public String toString() { return "Service{" + "id=" + id + ", nodeId=" + nodeId + ", type='" + type + '\'' + ", pool='" + pool + '\'' + ", location='" + location + '\'' + ", properties=" + properties + '}'; } @JsonCreator  Service(
            @JsonProperty("id") Id<Service> id,
            @JsonProperty("nodeId") Id<Node> nodeId,
            @JsonProperty("type") String type,
            @JsonProperty("pool") String pool,
            @JsonProperty("location") String location,
            @JsonProperty("properties") Map<String, String> properties); @JsonProperty Id<Service> getId(); @JsonProperty Id<Node> getNodeId(); @JsonProperty String getType(); @JsonProperty String getPool(); @JsonProperty String getLocation(); @JsonProperty Map<String, String> getProperties(); @Override boolean equals(Object o); @Override int hashCode(); static Predicate<Service> matchesType(final String type); static Predicate<Service> matchesPool(final String pool); @Override String toString(); static Builder copyOf(StaticAnnouncement announcement);  }
@Test public void testToJson() throws IOException { JsonCodec<Service> serviceCodec = JsonCodec.jsonCodec(Service.class); Service service = new Service(Id.<Service>valueOf("c0c5be5f-b298-4cfa-922a-3e5954208444"), Id.<Node>valueOf("3ff52f57-04e0-46c3-b606-7497b09dd5c7"), "type", "pool", "/location", ImmutableMap.of("key", "value")); String json = serviceCodec.toJson(service); JsonCodec<Object> codec = JsonCodec.jsonCodec(Object.class); Object parsed = codec.fromJson(json); Object expected = codec.fromJson(Resources.toString(Resources.getResource("service.json"), Charsets.UTF_8)); assertEquals(parsed, expected); }
@Test public void testParseJson() throws IOException { JsonCodec<Service> codec = JsonCodec.jsonCodec(Service.class); Service parsed = codec.fromJson(Resources.toString(Resources.getResource("service.json"), Charsets.UTF_8)); Service expected = new Service(Id.<Service>valueOf("c0c5be5f-b298-4cfa-922a-3e5954208444"), Id.<Node>valueOf("3ff52f57-04e0-46c3-b606-7497b09dd5c7"), "type", "pool", "/location", ImmutableMap.of("key", "value")); assertEquals(parsed, expected); }