Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think converters (<code>as JSON</code> syntax) will only work on domain objects and collections by default.</p> <p>To convert arbitrary objects you should use the <code>encodeAsJSON()</code> converter, I believe. Or use an object marshaller, where you tell the converter how to deal with your object.</p> <p>The docs aren't very clear on this though..</p> <p>See:</p> <ul> <li><a href="http://grails.org/Converters+Reference" rel="noreferrer">http://grails.org/Converters+Reference</a> (object marshalling section at bottom)</li> <li><a href="http://grails.org/doc/latest/ref/Plug-ins/codecs.html" rel="noreferrer">http://grails.org/doc/latest/ref/Plug-ins/codecs.html</a></li> </ul> <p>But I note that <a href="http://grails.org/doc/latest/api/grails/converters/JSON.html#JSON%28java.lang.Object%29" rel="noreferrer">http://grails.org/doc/latest/api/grails/converters/JSON.html#JSON%28java.lang.Object%29</a> says that the object converts POGOs.. Maybe it means if you have a marshaller?</p> <p>I did find this reference too:</p> <blockquote> <p>Notice that the ‘as’ operator is not overloaded for plain objects ...</p> <p>Domain objects can use the ‘as’ operator to cast an object to JSON, the same as a collection. So unlike POGOs, where they must be massaged into a list or have encodeAsJSON explictly called ...</p> <p><a href="http://manbuildswebsite.com/2010/02/08/rendering-json-in-grails-part-2-plain-old-groovy-objects-and-domain-objects/" rel="noreferrer">http://manbuildswebsite.com/2010/02/08/rendering-json-in-grails-part-2-plain-old-groovy-objects-and-domain-objects/</a></p> </blockquote> <p>Which seems to describe the situation.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload