Robert Coup created GEOS-4986:
---------------------------------
Summary: Creating SQL Views via RESTConfig as JSON fails
Key: GEOS-4986
URL: https://jira.codehaus.org/browse/GEOS-4986
Project: GeoServer
Issue Type: Bug
Components: REST
Affects Versions: 2.1.3
Reporter: Robert Coup
Assignee: Andrea Aime
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 [JSON RFC|http://www.ietf.org/rfc/rfc4627\]. 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\}}
Not working:
{code:javascript}
{
"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%"
}
}
]
},
...
}
}
{code}
Working (magic sequence order):
{code:javascript}
{
"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]+$"
}
]
}
}
]
},
...
}
}
{code}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://jira.codehaus.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira