20867

In JSON views, how do I flatten an object out as a single string?

Question:

In my grails 3 app (I'm using grails 3.2.4), I have an object type which I want to be serialized as a string, for any Domain object that uses it:

class MyDomain1 { CustomId id } class MyDomain2 { CustomId id }

I want to create a view that serializes CustomId as a string, rather than an object:

//instance of MyDomain1, in JSON format: { "id": "123" }

How can I do this without customizing the view for every object that uses CustomId?

Answer1:

Json views 1.2 supports a converter API that can do what you want

<a href="http://views.grails.org/latest/#_custom_converters" rel="nofollow">http://views.grails.org/latest/#_custom_converters</a>

Recommend

  • Push element into nested array mongoose nodejs
  • Domains are not being added, Whitelist domains facebook messenger extension
  • What going wrong in using PropertiesConfiguration?
  • Find rows with subset of values in another DataFrame, in a vectorized way
  • Left fixed columns with table colspan
  • Getting media player state in windows phone 7
  • Lock Horizontal View
  • Is there a way to save the selected text and highlight it again once the page is refreshed?
  • Debugging VB6 Code From Visual Studio 2010
  • Build Successful but not running on simulator
  • Button text different than value submitted in query string
  • How to revert to previous XCode version?
  • Should I or shouldn't I use the CachingConnectionFactory with hornetq 2.4.1
  • Get history of file changes from TFS to implement custom “blame”-behaviour of exceptions
  • iOS: Detect app start via notification press
  • Email verification using google app script and google forms
  • Meteor helpers not available in Angular template
  • Exception “firebase.functions() takes … no argument …” when specifying a region for a Cloud Function
  • Is calc() supported in html email?
  • req.body is undefined - nodejs
  • Symfony2: How to get request parameter
  • Akka Routing: Reply's send to router ends up as dead letters
  • Is there a mandatory requirement to switch app.yaml?
  • Cannot Parse HTML Data Using Android / JSOUP
  • Comma separated Values
  • How to delete a row from a dynamic generate table using jquery?
  • json Serialization in asp
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • Error creating VM instance in Google Compute Engine
  • Hits per day in Google Big Query
  • How get height of the a view with gone visibility and height defined as wrap_content in xml?
  • How do you join a server to an Active Directory (domain)?
  • how does django model after text[] in postgresql [duplicate]
  • Getting Messege Twice Using IMvxMessenger
  • Java static initializers and reflection
  • How to stop GridView from loading again when I press back button?
  • unknown Exception android
  • Observable and ngFor in Angular 2
  • Unable to use reactive element in my shiny app
  • How to load view controller without button in storyboard?