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

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Harry-2
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

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/fa0c355b-eb6f-4893-9056-b4d4c99a0db1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

rstevehole
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.

On Saturday, 25 February 2017 10:43:24 UTC-7, Harry wrote:
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: <a href="http://t.id" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Ft.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEoiT1FPq6FfTh7SSljhRcW36Ti2A&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Ft.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEoiT1FPq6FfTh7SSljhRcW36Ti2A&#39;;return true;">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

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/499e7d9d-0898-441c-98c9-bb9d08ada3e7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

Zachary Klein
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 the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
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.
Reply | Threaded
Open this post in threaded view
|

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

Harry-2
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 <[hidden email]> 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 [hidden email].
To post to this group, send email to [hidden email].
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 
615-957-5193



--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/CAEEvsq2-sE%2BDx0BnPfjUzC%3DCHTdxpKPRGxsEsURSLCn88q0rEA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.