Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6818545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:11:30+00:00 2026-05-26T21:11:30+00:00

I am marshaling objects in Grails to JSON using the JSON.registerObjectMarshaller() method, which is

  • 0

I am marshaling objects in Grails to JSON using the JSON.registerObjectMarshaller() method, which is invoked in the BootStrap class.

My object graph has a number of nested objects e.g. User -> Address -> Phone and I have a marshaller for each object.

I have a scenario where I want to be able to either return a “shallow” or “deep” version of the top level object. In the case of a shallow request, in place of the address I want to return the field. In the case of the a deep version, the other object marshalers can do delegated to as usual.

I want to do a deep versus shallow based on the value of a parameter passed in the request, however I do not know how to access request parameters when in the registerObjectMarshaller() method from the BootStrap class.

Once I have a way to access these parameters I can tailor it as needed.

Any pointers would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T21:11:31+00:00Added an answer on May 26, 2026 at 9:11 pm

    I once tried the object marshaller approach for XML and sadly it didn’t work out.
    Similar to you, I don’t have one way to represent objects. I have a lot more than two, but I think Object Marshallers are a way to go only if you want to do something trivial. If you need more, just forget about them.
    It may be much easier for you, to simply create a service or a class with static methods which will generate the JSON for you based on the values you pass.

    You can use JsonGroovyBuilder to achieve that, and then just convert it to string and wrap it in a nice http header or whatever you need.
    In my case it looks like this [mind you, this is for XML, so you have to use JsonGroovyBuilder, or other – whichever suits you – and you will probably not need to use the StringWriter as I do]:

        def writer = new StringWriter()
        def xml = new MarkupBuilder(writer)
    
        def retData = someService.doSomething()
    
        def xmlGen = new XmlResponseGenerator(xml, retData)
        render(contentType: 'text/xml', encoding: "UTF-8", text: writer.toString())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using RESTEasy to return Java objects as JSON objects (which is using Jettison
If a web service returns an object graph where some objects appear multiple times,
I got the following exception when marshalling Comment objects to JSON: javax.xml.bind.JAXBException: class javax.jdo.identity.LongIdentity
I have an external library which has a method which performs a long running
I am trying to flatten the xml output of xstream using a converter/marshaling with
I'm marshaling objects into an XML file. How can I add comments into that
I need to use Jackson to marshal and unmarshal json on arbitrary objects, and
I am using JAXB to marshall. I have noticed that when I am marshaling
I'm switching from Castor to JAXB2 to perform marshaling/unmarshaling between XML and Java object.
VB.NET 2010, .NET 4 Hello, I recently read about using SynchronizationContext objects to control

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.