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

geojson-jackson does not work when AUTO_DETECT_GETTERS is set to false #43

Open
Sil0x0000 opened this issue Aug 9, 2017 · 2 comments · May be fixed by #63
Open

geojson-jackson does not work when AUTO_DETECT_GETTERS is set to false #43

Sil0x0000 opened this issue Aug 9, 2017 · 2 comments · May be fixed by #63

Comments

@Sil0x0000
Copy link

When I try to use geojson-jackson it doesn't de serialize coordinates from point (for example when the default mapper feature AUTO_DETECT_GETTERS is set to false.

Is it possible to make geojson-jackson such that it also works when the this mapper setting is put diffrent then the default?

Best regards

@grundid
Copy link
Member

grundid commented Aug 10, 2017

I'm not familiar with the AUTO_DETECT_GETTERS option. The geojson objects use the standard bean convention.
Can you give an example how you handle your JSON objects?

@Sil0x0000
Copy link
Author

Sil0x0000 commented Aug 11, 2017

This is a feature of jackson to change the default behaviour of attribute detection. when this feature is not enabled (set to false) then there is need for explicitly identify which fields (or getter methods) are exposed through jackson serilization. I attached an exmaple:

Test.java

package test;

import org.geojson.Point;

import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;

public class TestGeoJson {

	private Point p1 = new Point(1.0, 10.0);
	
	
	public static void main(String[] args) throws Exception  {
		new TestGeoJson().test();
	}
	
	public void test() throws Exception {
		String json = getMapper().writeValueAsString(p1);

		System.out.println(json);
		
		Point copy = getMapper().readValue(json, Point.class);
		System.out.println(p1.equals(copy));
	}
	
	public ObjectMapper getMapper() {
		ObjectMapper m = new ObjectMapper();
		m.configure(MapperFeature.AUTO_DETECT_GETTERS, false);
		return m;
	}
	
}

pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>test</groupId>
	<artifactId>geo-json-test</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<build>
		<sourceDirectory>src</sourceDirectory>
		<plugins>
			<plugin>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.6.1</version>
				<configuration>
					<source>1.8</source>
					<target>1.8</target>
				</configuration>
			</plugin>
		</plugins>
	</build>

	<properties>
		<jackson.version>2.8.9</jackson.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>de.grundid.opendatalab</groupId>
			<artifactId>geojson-jackson</artifactId>
			<version>1.8</version>
		</dependency>
		<dependency>
			<groupId>com.fasterxml.jackson.core</groupId>
			<artifactId>jackson-databind</artifactId>
			<version>${jackson.version}</version>
		</dependency>
	</dependencies>
</project>

Note: my request is a feature request not a bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants