diff --git a/src/main/java/org/geojson/Crs.java b/src/main/java/org/geojson/Crs.java index 9aa203c..0ac28b0 100644 --- a/src/main/java/org/geojson/Crs.java +++ b/src/main/java/org/geojson/Crs.java @@ -2,10 +2,14 @@ import org.geojson.jackson.CrsType; +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; + import java.io.Serializable; import java.util.HashMap; import java.util.Map; +@JsonAutoDetect(getterVisibility = Visibility.PUBLIC_ONLY, setterVisibility = Visibility.PUBLIC_ONLY) public class Crs implements Serializable{ private CrsType type = CrsType.name; diff --git a/src/main/java/org/geojson/Feature.java b/src/main/java/org/geojson/Feature.java index 1d9c7fe..7c79153 100644 --- a/src/main/java/org/geojson/Feature.java +++ b/src/main/java/org/geojson/Feature.java @@ -1,10 +1,13 @@ package org.geojson; +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; import com.fasterxml.jackson.annotation.JsonInclude; import java.util.HashMap; import java.util.Map; +@JsonAutoDetect(getterVisibility = Visibility.PUBLIC_ONLY, setterVisibility = Visibility.PUBLIC_ONLY) public class Feature extends GeoJsonObject { @JsonInclude(JsonInclude.Include.ALWAYS) diff --git a/src/main/java/org/geojson/FeatureCollection.java b/src/main/java/org/geojson/FeatureCollection.java index ecde9bd..226b4ac 100644 --- a/src/main/java/org/geojson/FeatureCollection.java +++ b/src/main/java/org/geojson/FeatureCollection.java @@ -5,6 +5,10 @@ import java.util.Iterator; import java.util.List; +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; + +@JsonAutoDetect(getterVisibility = Visibility.PUBLIC_ONLY, setterVisibility = Visibility.PUBLIC_ONLY) public class FeatureCollection extends GeoJsonObject implements Iterable { private List features = new ArrayList(); diff --git a/src/main/java/org/geojson/GeoJsonObject.java b/src/main/java/org/geojson/GeoJsonObject.java index ed045f2..34a1bcc 100644 --- a/src/main/java/org/geojson/GeoJsonObject.java +++ b/src/main/java/org/geojson/GeoJsonObject.java @@ -3,6 +3,8 @@ import java.io.Serializable; import java.util.Arrays; +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; @@ -17,6 +19,7 @@ @Type(GeometryCollection.class) }) @JsonInclude(Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) +@JsonAutoDetect(getterVisibility = Visibility.PUBLIC_ONLY, setterVisibility = Visibility.PUBLIC_ONLY) public abstract class GeoJsonObject implements Serializable { private Crs crs; diff --git a/src/main/java/org/geojson/Geometry.java b/src/main/java/org/geojson/Geometry.java index 2f65fcd..191ba32 100644 --- a/src/main/java/org/geojson/Geometry.java +++ b/src/main/java/org/geojson/Geometry.java @@ -3,6 +3,10 @@ import java.util.ArrayList; import java.util.List; +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; + +@JsonAutoDetect(getterVisibility = Visibility.PUBLIC_ONLY, setterVisibility = Visibility.PUBLIC_ONLY) public abstract class Geometry extends GeoJsonObject { protected List coordinates = new ArrayList(); diff --git a/src/main/java/org/geojson/GeometryCollection.java b/src/main/java/org/geojson/GeometryCollection.java index b7fc809..379d655 100644 --- a/src/main/java/org/geojson/GeometryCollection.java +++ b/src/main/java/org/geojson/GeometryCollection.java @@ -4,6 +4,10 @@ import java.util.Iterator; import java.util.List; +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; + +@JsonAutoDetect(getterVisibility = Visibility.PUBLIC_ONLY, setterVisibility = Visibility.PUBLIC_ONLY) public class GeometryCollection extends GeoJsonObject implements Iterable { private List geometries = new ArrayList(); diff --git a/src/main/java/org/geojson/Point.java b/src/main/java/org/geojson/Point.java index 3f4f349..b21b1d5 100644 --- a/src/main/java/org/geojson/Point.java +++ b/src/main/java/org/geojson/Point.java @@ -1,5 +1,9 @@ package org.geojson; +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; + +@JsonAutoDetect(getterVisibility = Visibility.PUBLIC_ONLY, setterVisibility = Visibility.PUBLIC_ONLY) public class Point extends GeoJsonObject { private LngLatAlt coordinates; diff --git a/src/main/java/org/geojson/Polygon.java b/src/main/java/org/geojson/Polygon.java index d4c42af..b4906ec 100644 --- a/src/main/java/org/geojson/Polygon.java +++ b/src/main/java/org/geojson/Polygon.java @@ -3,8 +3,11 @@ import java.util.Arrays; import java.util.List; +import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; +@JsonAutoDetect(getterVisibility = Visibility.PUBLIC_ONLY, setterVisibility = Visibility.PUBLIC_ONLY) public class Polygon extends Geometry> { public Polygon() { diff --git a/src/test/java/org/geojson/NoAutoDetectGettersTest.java b/src/test/java/org/geojson/NoAutoDetectGettersTest.java new file mode 100644 index 0000000..d86ab9c --- /dev/null +++ b/src/test/java/org/geojson/NoAutoDetectGettersTest.java @@ -0,0 +1,43 @@ +package org.geojson; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +import com.fasterxml.jackson.databind.MapperFeature; +import com.fasterxml.jackson.databind.ObjectMapper; + + +public class NoAutoDetectGettersTest { + + private Feature testObject; + private ObjectMapper mapper; + + @Before + public void setUp() { + mapper = new ObjectMapper(); + mapper.configure(MapperFeature.AUTO_DETECT_GETTERS, false); + mapper.configure(MapperFeature.AUTO_DETECT_SETTERS, false); + + testObject = new Feature(); + testObject.setGeometry(new Polygon(new LngLatAlt(15, 58))); + } + + + @Test + public void itShouldSerializePropertiesAndGeometry() throws Exception { + // Make sure that the serialized object contains properties and + // geometry (that are defined using getters/setters), even though + // auto detect getters & setters are disabled on the ObjectMapper. + + assertEquals("{\"type\":\"Feature\",\"properties\":{},\"geometry\":{\"type\":\"Polygon\",\"coordinates\":[[[15.0,58.0]]]}}", + mapper.writeValueAsString(testObject)); + } + + @Test + public void itShouldParsePropertiesAndGeometry() throws Exception { + Feature feature = mapper.readValue("{\"type\":\"Feature\",\"properties\":{},\"geometry\":{\"type\":\"Polygon\",\"coordinates\":[[[15.0,58.0]]]}}", Feature.class); + assertEquals(testObject, feature); + } +} \ No newline at end of file