@Test public void shouldExcludeHeadingEqualTo360() throws Exception { location.heading = 360; assertThat(locationSerializer.serialize(location, JSON.Location.class, null).toString()) .doesNotContain("\"heading\":360"); }
@Override public JsonElement serialize(JSON.Location src, Type typeOfSrc, JsonSerializationContext context) { JsonObject jsonObject = (JsonObject) new GsonBuilder().create().toJsonTree(src); if (src.heading < 0 || src.heading >= 360) { jsonObject.remove("heading"); } return jsonObject; }
LocationSerializer implements JsonSerializer<JSON.Location> { @Override public JsonElement serialize(JSON.Location src, Type typeOfSrc, JsonSerializationContext context) { JsonObject jsonObject = (JsonObject) new GsonBuilder().create().toJsonTree(src); if (src.heading < 0 || src.heading >= 360) { jsonObject.remove("heading"); } return jsonObject; } }
LocationSerializer implements JsonSerializer<JSON.Location> { @Override public JsonElement serialize(JSON.Location src, Type typeOfSrc, JsonSerializationContext context) { JsonObject jsonObject = (JsonObject) new GsonBuilder().create().toJsonTree(src); if (src.heading < 0 || src.heading >= 360) { jsonObject.remove("heading"); } return jsonObject; }  }
LocationSerializer implements JsonSerializer<JSON.Location> { @Override public JsonElement serialize(JSON.Location src, Type typeOfSrc, JsonSerializationContext context) { JsonObject jsonObject = (JsonObject) new GsonBuilder().create().toJsonTree(src); if (src.heading < 0 || src.heading >= 360) { jsonObject.remove("heading"); } return jsonObject; }  @Override JsonElement serialize(JSON.Location src, Type typeOfSrc,
      JsonSerializationContext context); }
LocationSerializer implements JsonSerializer<JSON.Location> { @Override public JsonElement serialize(JSON.Location src, Type typeOfSrc, JsonSerializationContext context) { JsonObject jsonObject = (JsonObject) new GsonBuilder().create().toJsonTree(src); if (src.heading < 0 || src.heading >= 360) { jsonObject.remove("heading"); } return jsonObject; }  @Override JsonElement serialize(JSON.Location src, Type typeOfSrc,
      JsonSerializationContext context);  }