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

Can not construct instance of org.geojson.GeoJsonObject #56

Open
porunov opened this issue Jul 30, 2020 · 1 comment
Open

Can not construct instance of org.geojson.GeoJsonObject #56

porunov opened this issue Jul 30, 2020 · 1 comment

Comments

@porunov
Copy link

porunov commented Jul 30, 2020

Cannot parse a valid GeoJSON string via readValue(geoJson, GeoJsonObject.class);.

Here is the code to reproduce the exception:

String geoJson = "{\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"geometry\":{\"type\":\"Polygon\",\"coordinates\":[[[-126.456789,-2.123,0.0],[-123.456789,2.123,0.0],[-124.456789,2.123,0.0],[-125.456789,-2.123,0.0],[-126.456789,-2.123,0.0]]]},\"properties\":{\"myProp\":\"PropData1\"}},{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[-123.123,55.555,0.0]},\"properties\":{\"myProp\":\"PropData2\"}},{\"type\":\"Feature\",\"geometry\":{\"type\":\"Polygon\",\"coordinates\":[[[123.456789,2.123,0.0],[-123.456789,2.123,0.0],[-124.456789,2.123,0.0],[-125.456789,-2.123,0.0],[123.456789,2.123,0.0]]]},\"properties\":{\"myProp\":\"PropData3\"}},{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[-15.123,75.555,0.0]},\"properties\":{\"myProp\":\"PropData4\"}}]}";

GeoJsonObject object = new ObjectMapper().readValue(geoJson, GeoJsonObject.class);

The log is the next:

Can not construct instance of org.geojson.GeoJsonObject, problem: abstract types can only be instantiated with additional type information
 at [Source: java.io.StringReader@aa0657b; line: 1, column: 1]
org.codehaus.jackson.map.JsonMappingException: Can not construct instance of org.geojson.GeoJsonObject, problem: abstract types can only be instantiated with additional type information
 at [Source: java.io.StringReader@aa0657b; line: 1, column: 1]
	at org.codehaus.jackson.map.JsonMappingException.from(JsonMappingException.java:163)
	at org.codehaus.jackson.map.deser.StdDeserializationContext.instantiationException(StdDeserializationContext.java:233)
	at org.codehaus.jackson.map.deser.AbstractDeserializer.deserialize(AbstractDeserializer.java:60)
	at org.codehaus.jackson.map.ObjectMapper._readMapAndClose(ObjectMapper.java:2732)
	at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1863)

For convince here is the geoJson which I try to parse:

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [
            [
              -126.456789,
              -2.123,
              0.0
            ],
            [
              -123.456789,
              2.123,
              0.0
            ],
            [
              -124.456789,
              2.123,
              0.0
            ],
            [
              -125.456789,
              -2.123,
              0.0
            ],
            [
              -126.456789,
              -2.123,
              0.0
            ]
          ]
        ]
      },
      "properties": {
        "myProp": "PropData1"
      }
    },
    {
      "type": "Feature",
      "geometry": {
        "type": "Point",
        "coordinates": [
          -123.123,
          55.555,
          0.0
        ]
      },
      "properties": {
        "myProp": "PropData2"
      }
    },
    {
      "type": "Feature",
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [
            [
              123.456789,
              2.123,
              0.0
            ],
            [
              -123.456789,
              2.123,
              0.0
            ],
            [
              -124.456789,
              2.123,
              0.0
            ],
            [
              -125.456789,
              -2.123,
              0.0
            ],
            [
              123.456789,
              2.123,
              0.0
            ]
          ]
        ]
      },
      "properties": {
        "myProp": "PropData3"
      }
    },
    {
      "type": "Feature",
      "geometry": {
        "type": "Point",
        "coordinates": [
          -15.123,
          75.555,
          0.0
        ]
      },
      "properties": {
        "myProp": "PropData4"
      }
    }
  ]
}
@JoaoEmanoelConinch
Copy link

It happens to me too.
Did you solve the problem?
Could you help me?

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

No branches or pull requests

2 participants