How to exclude parameters from XML presented in Grails?

I have a class:

class Category { String name SortedSet items static hasMany = [items:Item] } 

Inside the controller, I present the category as XML (converters):

  def getCategory = { render Category.read(1) as XML } 

But I want to exclude elements from rendering.

How can i do this?

thanks

+4
source share
3 answers

You can simply return a Map with only the properties you want to include:

 def getCategory = { def category = Category.read(1) render [ id: category.id, name: category.name ] as XML } 
+1
source

You need to create a second class of the domain class similar to the view and configure the mapping so that it has the same table as the Category class

See the whole answer in this thread: How to limit the visibility of domain properties in grails?

Fabienne.

0
source

Another option is to use the marshallers plugin. It allows you to define a custom marshaller either on the object itself or elsewhere. For instance:

 class Category { String name SortedSet items static hasMany = [items:Item] static marshallers { shouldOutputIdentifier false shouldOutputVersion false shouldOutputClass false elementName 'category' attribute 'name' } } 
0
source

Source: https://habr.com/ru/post/1309758/


All Articles