Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for ObjectMapper AUTO_DETECT_GETTERS and AUTO_DETECT_SETTERS set to false #63

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/main/java/org/geojson/Crs.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/geojson/Feature.java
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/geojson/FeatureCollection.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Feature> {

private List<Feature> features = new ArrayList<Feature>();
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/geojson/GeoJsonObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/geojson/Geometry.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> extends GeoJsonObject {

protected List<T> coordinates = new ArrayList<T>();
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/geojson/GeometryCollection.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<GeoJsonObject> {

private List<GeoJsonObject> geometries = new ArrayList<GeoJsonObject>();
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/geojson/Point.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/geojson/Polygon.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<List<LngLatAlt>> {

public Polygon() {
Expand Down
43 changes: 43 additions & 0 deletions src/test/java/org/geojson/NoAutoDetectGettersTest.java
Original file line number Diff line number Diff line change
@@ -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);
}
}