Grails - grails.converters.JSON - removing the class name

后端 未结 7 827
梦如初夏
梦如初夏 2020-12-16 00:14

Is there a way to remove the class field in a JSON converter?

Example:

import testproject.*
import grails.converters.*  
emp = new Employee()  
emp         


        
相关标签:
7条回答
  • 2020-12-16 00:55

    One alternative is to not use the builder:

    def myAction = {
        def emp = new Employee()
        emp.lastName = 'Bar'
    
        render(contentType: 'text/json') {
            id = emp.id
            lastName = emp.lastName
        }
    }
    

    This is a bit less orthogonal since you'd need to change your rendering if Employee changes; on the other hand, you have more control over what gets rendered.

    0 讨论(0)
提交回复
热议问题