| 1 | |
| 2 | = !MapGuide RFC 152 - Add mapagent support for GeoJSON and simplified JSON responses = |
| 3 | |
| 4 | This page contains a change request (RFC) for the !MapGuide Open Source project. |
| 5 | More !MapGuide RFCs can be found on the [wiki:MapGuideRfcs RFCs] page. |
| 6 | |
| 7 | == Status == |
| 8 | |
| 9 | ||RFC Template Version||(1.0)|| |
| 10 | ||Submission Date||19 Nov 2015|| |
| 11 | ||Last Modified||19 Nov 2015|| |
| 12 | ||Author||Jackie Ng|| |
| 13 | ||RFC Status||draft|| |
| 14 | ||Implementation Status||sandbox experimental|| |
| 15 | ||Proposed Milestone||3.1|| |
| 16 | ||Assigned PSC guide(s)||(when determined)|| |
| 17 | ||'''Voting History'''||(vote date)|| |
| 18 | ||+1|||| |
| 19 | ||+0|||| |
| 20 | ||-0|||| |
| 21 | ||-1|||| |
| 22 | ||no vote|| || |
| 23 | |
| 24 | == Overview == |
| 25 | |
| 26 | This RFC proposes to simplify all JSON responses from the mapagent, and adding GeoJSON output for SELECTFEATURES |
| 27 | |
| 28 | == Motivation == |
| 29 | |
| 30 | All JSON responses from the mapagent are verbatim conversions from their XML counterparts. |
| 31 | |
| 32 | However this conversion process results in JSON that is quite cumbersome to consume: |
| 33 | |
| 34 | * All properties are arrays. |
| 35 | * All properties are string values. |
| 36 | |
| 37 | This is due to the conversion process not taking the content model (and its data types/element cardinality) into account, taking the lowest common denominator approach. |
| 38 | |
| 39 | Also for the SELECTFEATURES operation, the JSON response in its current form is horribly un-usable. A more practical and ubiquitous JSON format for feature data already exists: GeoJSON |
| 40 | |
| 41 | == Proposed Solution == |
| 42 | |
| 43 | The MgJsonConvert class that does the actual XML to JSON conversion will be modified to include a hard-coded list of XML element paths: |
| 44 | |
| 45 | * For elements that contain 0 to many elements |
| 46 | * For elements that are not string data types |
| 47 | |
| 48 | During the conversion process, we check the computed XML element path of the element we're converting and check if it is in one of these two lists |
| 49 | |
| 50 | * If it is in the first list, the element is written as a JSON array |
| 51 | * If it is in the second list, the element will not have its value quoted |
| 52 | |
| 53 | To retain compatibility with clients using the JSON responses of the older mapagent, using simplified JSON responses is opt-in, by including CLEAN=1 as part of your mapagent request parameters. |
| 54 | When this parameter is not specified or set to 0, the old XML to JSON conversion behaviour will be used. |
| 55 | |
| 56 | For the SELECTFEATURES operation, when CLEAN=1 is specified the response format will be GeoJSON |
| 57 | |
| 58 | With the new JSON responses, not only are they more intuitive to use (not everything is an array and not everything is a string), but is also much more compact due to |
| 59 | the amount of {{{[}}} and {{{"}}} characters we save by not converting everything to string arrays |
| 60 | |
| 61 | == Implications == |
| 62 | |
| 63 | Any time a new schema or schema revision is introduced, this hard-coded list will have to be updated to know which elements in these new schemas require special processing. |
| 64 | |
| 65 | == Test Plan == |
| 66 | |
| 67 | Verify all new JSON response parse as valid JSON. |
| 68 | |
| 69 | == Funding / Resources == |
| 70 | |
| 71 | Community |