AnsweredAssumed Answered

Controller and JSON

Question asked by sihnu on Mar 17, 2015
Latest reply on Mar 17, 2015 by muralidharand
Hi,

in our current project we have created a webscript that starts a workflow by definition name. The webscript works fine. Now problem is that there are some bunch of properties that should be multiplied. We thought different scenarios to solve this problem and finally we came up with a solution where we send the collection of properties (lets say it was employee with properties name, address and age) as json object. Now the idea is to create a custom controller that parses and iterates the json creating fields for every item in the list (for every employee).

I managed to send json as a property but now I'm having problems with json parsing in freemarker template of my controller.I have googled for the solution and I stumbled couple of times in simple solution that seems to work fine for those ppl.


// assign json to employeelist and loop it like:

<#list employeelist as emp>
${emp.name}


But this doesn't work in my solution.I get error "Expected collection or sequence…" So it seems freemarker is not seeing the property as json object but rather as plain string. How can I tell freemarker that it is actually iterable json-object (a list)? I've tried to google with keywords "freemarker convert string to json" but no luck so far. This is small thing but really preventing me from continuing. Btw, here is the json I use to test:


[{"name": "Fred Bloggs", "email": "fred@test.com", "id": "123456"},{"name": "John Smith", "email": "john@test.com", "id": "456789"},{"name": "Bob Brown", "email": "bob@test.com", "id": "987654"}]


(and the value comes to the controller like that. I had to escape the " marks as \" though but the json comes without the escapes to the controller (like above). I tested it.

I would be really happy if someone could help me here. Thanks in advance.

Outcomes