Creating SQL Views via RESTConfig as JSON fails

Description

Goal: Create a SQL View via REST config, using the JSON API format.

Problem: org.geoserver.config.util.XStreamPersister.VirtualTableConverter.unmarshal() parses the JSON for the virtual-table declaration in the POST in a sequence-specific way. This is fine for XML, but the equivalent JSON uses an object, which is meant to be unordered as per the http://www.ietf.org/rfc/rfc4627 - JSON RFC. Depending on the language/library generating the JSON, it can be really hard to get it in a defined order (and it's not obvious that's the problem... errors are about missing keys).

Example:
POST to: http://localhost:8080/geoserver/rest/workspaces/my/datastores/my_database/featuretypes.json - http://localhost:8080/geoserver/rest/workspaces/my/datastores/my_database/featuretypes.json

Not working:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 { "featureType": { ... "metadata": { "entry": [ ... { "@key": "JDBC_VIRTUAL_TABLE", "virtualTable": { "geometry": { "type": "Polygon", "name": "my_geometry", "srid": 5479 }, "keyColumn": "my_pk", "parameter": [ { "regexpValidator": "^[\\w\\d\\s]+$", "name": "from" }, { "regexpValidator": "^[\\w\\d\\s]+$", "name": "to" } ], "name": "foo", "sql": "SELECT * FROM foo WHERE my_field BETWEEM %from% AND %to%" } } ] }, ... } }

Working (magic sequence order):

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 { "featureType": { ... "metadata": { "entry": [ ... { "@key": "JDBC_VIRTUAL_TABLE", "virtualTable": { "name": "foo", "sql": "SELECT * FROM foo WHERE my_field BETWEEM %from% AND %to%", "keyColumn": "my_pk", "geometry": { "name": "my_geometry", "type": "Polygon", "srid": 5479 }, "parameter": [ { "name": "from", "regexpValidator": "^[\\w\\d\\s]+$" }, { "name": "to", "regexpValidator": "^[\\w\\d\\s]+$" } ] } } ] }, ... } }

Environment

None

Status

Assignee

Unassigned

Reporter

codehaus

Triage

None

Fix versions

Affects versions

2.1.3

Components

Priority

Medium
Configure