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 567191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:03:25+00:00 2026-05-13T13:03:25+00:00

I have a domain object on which I want to store a few things

  • 0

I have a domain object on which I want to store a few things which only exist at runtime. I looked at the documentation and found the transients keyword, which, on the face of it was what I was looking for. Here is what my domain object looks like…

class Contact {

    def Seeker

    def beforeInsert() 
    {
       initiatedDate = new Date()
    }

    Date initiatedDate
    Date acceptedDate

    static transients = ['pal']
    Seeker pal
}

where Seeker is a groovy class which is not a domain object, but a placeholder for some properties.

So far all is fine and my Contact table does not have a pal field as expected. In my ContactController I query for a bunch of contacts, c, then look up their Seeker pals (details of how withheld) and set the pal field to a new object.

c.pal = new Seeker();
c.pal.name = otherObject.name
render c as JSON

This all seems to work fine except that the pal object is missing from the JSON returned.

Is this a valid use of transients? The docs mention that they are handy for function-based getters and setters, but in my case I want an actual object. Should I be writing a getPal() and setPal() method on my object?

Thanks

  • 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-13T13:03:26+00:00Added an answer on May 13, 2026 at 1:03 pm

    Transients are indeed used to stop fields in domain objects from being persisted. (If you want to perform some init on the pal field without having to put it in your controller you could use the onLoad() event or write a getPal() method which would override the default property getter). You are also right to note that the default JSON marshaller only renders persisted fields.

    When rendering my domain objects I’ve found it useful to create JSON object marshallers so that unwanted properties are not rendered, but it would also solve your transient issue too. You can do this using the JSON.registerObjectMarshaller method:

    import grails.converters.JSON
    ...
    class BootStrap {
    
        def init = {servletContext ->
            JSON.registerObjectMarshaller(Contact ) {
                def returnArray = [:]
                returnArray['id'] = it.id
                returnArray['initiatedDate'] = it.initiatedDate
                returnArray['acceptedDate'] = it.acceptedDate
                returnArray['pal'] = it.pal
                return returnArray
            }
    
            JSON.registerObjectMarshaller(Seeker) {
                ...
            }
    

    If you add the marshallers in your BootStrap.groovy they will be available in your controllers.

    HTH

    (Also found this: http://old.nabble.com/Taggable-plugin-and-JSON-converter-ts24830987.html#a24832970)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this huge domain object(say parent) which contains other domain objects. It takes
I have a an object stored in the model called domain, which has two
I have an important Object which have loads of properties. Now few of the
My use case is simple. I have a root domain object which references a
I have a backend system that currently returns a domain object. I want to
I have a domain class which has two dates in it and I want
I have a domain object that has been auto generated for me by MyGeneration.
I have my domain object, Client , I've got a form on my JSP
Assume I have this domain object... public class SpansMultipleTables { public int CommonID {get;
When you have a domain object that needs to display as an interface 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.