Grails 3 with JSON rendering with Expando , how to to skip metadata

48 views
Skip to first unread message

Harry

unread,
Feb 25, 2017, 12:43:24 PM2/25/17
to Grails Dev Discuss
Hi All,

 I have an issue in rendering expando as JSON , i have JSON.registerObjectMarshaller in my Bootstrap.groovy approvers is a Expando array, My JSON output is full of MetaExpandoProperty , but i want to skip that and just render the property key and values, Please me know on how to achieve this , appreciate your response


Bootstrap.groovy 

JSON.registerObjectMarshaller(Timesheet, {  Timesheet t ->
return [
id: t.id,  
approvers:t.approvers
]
 });

JSON outout :

{
  "id": 10,
  
  "approvers": [
    {
      "metaPropertyValues": [
        {
          "class": "groovy.lang.MetaExpandoProperty",
          "modifiers": 1,
          "name": "role",
          "type": "java.lang.Object"
        },
        {
          "class": "groovy.lang.MetaExpandoProperty",
          "modifiers": 1,
          "name": "name",
          "type": "java.lang.Object"
        }
      ],
      "properties": {
        "role": "XXXX",
        "name": "XXXXX",
        
      }
    }
  ]
}

regards,
Harish

Steve Hole

unread,
Mar 23, 2017, 9:58:26 AM3/23/17
to Grails Dev Discuss
I've never really gotten this to work. I've always had to marshal to a Map or simple bean object and then do the JSON work. Painful to be sure.

Zachary Klein

unread,
Mar 29, 2017, 1:55:16 AM3/29/17
to Grails Dev Discuss
Have you tried using JSON views? http://views.grails.org

Here's a quick intro video: https://m.youtube.com/watch?v=ROwKJZJSTQc

Harish M A

unread,
Mar 29, 2017, 8:37:53 AM3/29/17
to grails-de...@googlegroups.com
I did like the suggestion , converted expando to Map and then sticked that to the Json ..

Thanks for the suggestion .. it worked 

On Wed, Mar 29, 2017 at 12:55 AM Zachary Klein <z...@silver-chalice.com> wrote:
Have you tried using JSON views? http://views.grails.org

Here's a quick intro video: https://m.youtube.com/watch?v=ROwKJZJSTQc

--
You received this message because you are subscribed to a topic in the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/grails-dev-discuss/MNC0qP-AfLY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to grails-dev-disc...@googlegroups.com.
To post to this group, send email to grails-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/aec96cd1-fc88-49fc-8a13-9901280161bc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Regards,
Harish 



Reply all
Reply to author
Forward
0 new messages