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

  • Home
  • SEARCH
  • 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 9221611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:36:53+00:00 2026-06-18T03:36:53+00:00

For the following domain model: class Route { String name static hasMany = [checkPoints:CheckPoint]

  • 0

For the following domain model:

class Route {
    String  name
    static  hasMany     = [checkPoints:CheckPoint]  
    static  belongsTo   = [someBigObject:SomeBigObject]


    static mapping = {
        checkPoints lazy: false
    }
}

I need to return a specific Route as a JSON from a web service. And I want this JSON to contain all the checkPoints but no other compositions (i.e.:someBigObject).

If I do

def route = Route.findById(id)
render route as JSON

all I got is the id’s of the checkPoints, no other field is fetched:

{
    "class": "com.example.Route",
    "id": 1,
    "checkPoints": [
        {
            "class": "CheckPoint",
            "id": 1
        },
        {
            "class": "CheckPoint",
            "id": 2
        },
        {
            "class": "CheckPoint",
            "id": 4
        },
        {
            "class": "CheckPoint",
            "id": 3
        }
    ],
    "someBigObject": {
        "class": "SomeBigObject",
        "id": 2
    }
}

but if I do

JSON.use('deep') {
    render route as JSON
}

I get everything. I mean, almost all the database is getting fetched through various relationships.

Is there way to do this without creating the jsonMaps manually?

  • 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-06-18T03:36:54+00:00Added an answer on June 18, 2026 at 3:36 am

    You can register your own JSON marshaller for chosen classes and return properties which you want to render. Map can be done automatically by iteration over class fields. Marshaller ca be registered for example in bootstrap or in domain class during creation.

    JSON.registerObjectMarshaller(Route) {
        return [name:it.name, checkPoints:it.checkPoints]
    }
    

    There is nice article about it under: http://manbuildswebsite.com/2010/02/15/rendering-json-in-grails-part-3-customise-your-json-with-object-marshallers/

    Hope it helps

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

Sidebar

Related Questions

The following domain model definition .. class Test { String a String b static
I have the following domain model: public class Name { private readonly string fullName;
I have the following Grails domain class: class Product { String name Float basePrice
I have the following domain: public class FileInformation { public String FileName; public String
I have the following model class DNS(models.Model): domain = models.ForeignKey(Domain) host_start = models.CharField(max_length=150, blank=True,
In my domain model I have following Classes.A 'UserProfile' has one 'SecurityPrincipal' class SecurityPrincipal{
What do you think of the following table mapping style for domain entities? class
I have a Domain model that countains the following properties : public class Profile
Consider the following (simplified) domain model stored in RavenDB: public abstract class PriceCalculation {
I have the following domain model setup using EF code first: public class User

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.