Key/Value field returns Keys without spaces in velocity
I have a structure with a field: specifications of type Key/Value field.
In the database the data is saved as a string like this: "{"Product Height (with stand)":"32-1/2","Product Height (without stand)":"29-3/4","DLNA":"Yes","TV Type":"LED Flat-Panel ","Product Weight":"56.2 lbs. with stand (48.3 lbs. without)","USB Port":"Yes","USB Input":"Yes"}"
When I pull the content on the page and I print the object field
$con.specifications
I get the same value as above which is correct.
Then I use velocity to loop over the fields to print each key and value and the keys come back without spaces or special characters like this USBInput: Yes USBPort: Yes ProductHeightwithstand: 32-1/2 ProductWeight: 56.2 lbs. with stand (48.3 lbs. without) ProductHeightwithoutstand: 29-3/4 TVType: LED Flat-Panel DLNA: Yes
See my code here: https://gist.github.com/2490753
Jorge sent me the code that creates the JSON object returned and you can see it's stripping everything except letters. https://gist.github.com/2490662
We need to have a way to display this data on a widget with the correct spaces and characters as it was saved.
imagine that we let the spaces there. Then
$con.someKVfield.Product Height (with stand)
will not be a valid velocity sentence to get the value of that key.
My thinking here is that JSONTool should be modified to receive a string with raw JSON. Currently it only receives an url or a map.
Something like
#set( $jsonObj = $json.fromJSON($con.someKVfield.toString()) )
then we can work with $jsonObj that have .keys() .get() ...
The solution here was to include an additional property to the result, named "map", that includes the rawMap, thus it can be iterated and its keys are left as they are (with spaces and special characters) :
Example usage:
#foreach($con in $dotcontent.pull("+structureName:Products",10,"modDate desc"))
#foreach ($map in $con.specs.map.entrySet()) $map.key $map.value #end
#end
Great :) Thanks!
Prasad will QA test