Home JSON marshaller ignored when rendering object with child objects
Reply: 0

JSON marshaller ignored when rendering object with child objects

user1061
1#
user1061 Published in June 20, 2018, 1:35 am

Currently running grails 3.2.10

Given the following domains

class Form {
  List<Step> steps
  static hasMany = [steps:Step]
}

class Step {
  Form form
  static belongsTo = [Form]
  String docID
  String stepRef
}

When trying to view the JSON representation of the form render Form as JSON, the list of Steps is rendered as a list of IDs, e.g., "steps":[{"id":15},{"id":16},{"id":17},{"id":18}]

Ok, so I set up a JSON marshaller and registered it in BootStrap: JSON.registerObjectMarshaller(new StepMarshaller())

The StepMarshaller just renders the the important fields. When I call this directly, it works just fine:

render Step.get(1) as JSON

yields the correct JSON ({"docID":"The_ID","stepRef":"1"})

However, rendering the parent Form as JSON still returns the list of IDs (the default behavior). What am I missing that's causing the Marshaller to be ignored for child objects?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.300271 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO