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

JSON marshaller ignored when rendering object with child objects

Trebla Published in 2018-01-09 13:38:12Z

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?

Evgeny Smirnov
Evgeny Smirnov Reply to 2018-01-10 06:59:58Z

You may use default deep json converter:

   render (form as JSON) 
You need to login account before you can post.

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

© 2016 Powered by mzan.com design MATCHINFO