1

In grails I am trying to return parameters back to the ui. In my controller I respond with a map. The problem I have is the domain objects for example parent and child end up double wrapped.

Map paramsdata = [
        child: parent.child,
        parent: parent,
    ]

    respond( paramsdata )

so my response is something like this

"child":{"child":{all properties here}}, "parent":{"parent":{all properties here}}

This means in the ui I have to do something like response.get('parent').get('parent')

I have tried a lot of different ways to get this to work how I would like but nothing seems to work.

Luke
  • 11
  • 2
  • How exactly would you like it to work? – Yaro Sep 01 '15 at 17:23
  • Your `ui` is gsp, javascript or other? What is the expected format of the response? – lifeisfoo Sep 01 '15 at 17:31
  • I want to get a map of two domain objects "child":{all properties here}, "parent":{all properties here}. So that I can use javascript and say response.get('parent') and not have to call get('parent') twice. I use a javascript backbone front end. The javascript is expecting JSON back and respond is returning everything as JSON. – Luke Sep 01 '15 at 17:54
  • Can you show what's in the parent.child and parent variables? – Emmanuel Rosa Sep 01 '15 at 18:46
  • I can give an example but I am not sure why it is important. I am just asking basically what is the best way to pass back multiple domain objects back to the UI without double wrapping them. The Parent object has one child and probably a name and what ever other generic attributes. These are not the actual objects I am trying to send back to the ui. I am passing a map of about 10 things and everything comes through just fine except the two domain objects are double wrapped. – Luke Sep 01 '15 at 19:11
  • It's important because of what @Aston said in his answer. For both the reason, and his suggestion that there must be a better way. – Emmanuel Rosa Sep 01 '15 at 20:30

1 Answers1

1

Your 'parent' and 'parent.child' values are already maps with 'parent' and 'child' entries. So, if on the UI you want it simpler:

Map paramsdata = [
    child: parent.child.child,
    parent: parent.parent,
]

respond( paramsdata )

But as you can see there must be a way to prevent this before you create your 'paramsdata'.

Aston
  • 3,654
  • 1
  • 21
  • 18