camptocamp/mapfish-printV3 — pull request #138 by jesseeichar (2014-09-20 05:25:34+00:00)
Title: Hack to make GeoJSON parsing more reliable

Hack to make GeoJSON parsing more reliable.

Geotools json parser has a problem in that it builds the feature type based on first feature in collection but GeoJSON specification says that not all features need the same properties (attributes), so in the case where the later features have more or different properties from the first feature, the parsing will fail.

This change parses GeoJSON to create a feature type by processing all properties in the collection first, then as a second pass using the geotools parser with the created feature type. In this case the parsing is robust.

The main problem is that this solution uses too much memory. We parse the geojson string into a JSONObject object structure which takes a lot of memory for large GeoJSON documents. It would be better to use a streaming parser to create the feature type, instead of the JSONObject parsing. This would take the same amount of time but would not use so much memory.

For performance it would be better to implement a changeable FeatureType class and create a custom parser that adds attributes to the feature type as needed. This could be tricky though so first we should do the streaming parsing for the feature type creation.