@Test public void testJson() throws Exception { ObjectMapper mapper = new ObjectMapper(); Geopoint point = Geopoint.of(-73.9857, 40.7484); String json = mapper.writeValueAsString(point); String expected = "{\"type\":\"Point\",\"coordinates\":[-73.9857,40.7484]}"; assertEquals(expected, json); Geopoint back = mapper.readValue(json, Geopoint.class); assertEquals(back, point); }
public static Geopoint of(double lng, double lat) { if (Math.abs(lng) > 180) { throw new IllegalArgumentException("invalid longitude: " + lng); } if (Math.abs(lat) > 90) { throw new IllegalArgumentException("invalid latitude: " + lat); } return new AutoValue_Geopoint(ImmutableList.of(lng, lat)); }
Geopoint { public static Geopoint of(double lng, double lat) { if (Math.abs(lng) > 180) { throw new IllegalArgumentException("invalid longitude: " + lng); } if (Math.abs(lat) > 90) { throw new IllegalArgumentException("invalid latitude: " + lat); } return new AutoValue_Geopoint(ImmutableList.of(lng, lat)); } }
Geopoint { public static Geopoint of(double lng, double lat) { if (Math.abs(lng) > 180) { throw new IllegalArgumentException("invalid longitude: " + lng); } if (Math.abs(lat) > 90) { throw new IllegalArgumentException("invalid latitude: " + lat); } return new AutoValue_Geopoint(ImmutableList.of(lng, lat)); }  }
Geopoint { public static Geopoint of(double lng, double lat) { if (Math.abs(lng) > 180) { throw new IllegalArgumentException("invalid longitude: " + lng); } if (Math.abs(lat) > 90) { throw new IllegalArgumentException("invalid latitude: " + lat); } return new AutoValue_Geopoint(ImmutableList.of(lng, lat)); }  String getType(); abstract List<Double> getCoordinates(); @JsonIgnore double getLng(); @JsonIgnore double getLat(); @JsonIgnore double getDistanceTo(Geopoint other); static Geopoint of(double lng, double lat); @JsonCreator static Geopoint of(@JsonProperty("type") String type, @JsonProperty("coordinates") List<Double> coordinates); }
Geopoint { public static Geopoint of(double lng, double lat) { if (Math.abs(lng) > 180) { throw new IllegalArgumentException("invalid longitude: " + lng); } if (Math.abs(lat) > 90) { throw new IllegalArgumentException("invalid latitude: " + lat); } return new AutoValue_Geopoint(ImmutableList.of(lng, lat)); }  String getType(); abstract List<Double> getCoordinates(); @JsonIgnore double getLng(); @JsonIgnore double getLat(); @JsonIgnore double getDistanceTo(Geopoint other); static Geopoint of(double lng, double lat); @JsonCreator static Geopoint of(@JsonProperty("type") String type, @JsonProperty("coordinates") List<Double> coordinates);  }