【问题标题】:Grails 3 : Class inheritance not working with json-viewsGrails 3:类继承不适用于 json-views
【发布时间】:2017-02-08 01:37:36
【问题描述】:

我正在尝试从多态查询的结果中呈现 json 视图。 使用对象编组器,它可以完美地工作,但不能使用 grails3 json-views。 我尝试了各种各样的东西,这似乎是 json-views 插件中的一个错误。

这是一个澄清问题的例子:

class Content {
 String text
}

class BlogEntry extends Content {
    URL url
}

class Book extends Content {
    String ISBN
}

在 contentController 中:

class ContentController extends RestfulController<Content> {

    static responseFormats = ['json', 'xml']

    ContentController() {
        super(Content)
    }

    def index(Integer max) {
        println '*CONTENT:INDEX*'
        def contents= Content.findAll()
        respond contents 
    }
}

json 视图:

// /content/index.gson
model {
    Iterable<Content> contentList
}

json tmpl.content(contentList ?: [])

// /content/_content.gson
model {
    Content content
}

json g.render(content)

我从控制器的 index 方法中得到一个空结果。我正在使用带有 views-json:1.1.0.RC3 的 grails 3.2.0.RC2

使用自定义对象编组器,我可以按子类类型(BlogEntry、Book)获取 json 结果,这是预期的结果。

【问题讨论】:

    标签: inheritance grails polymorphism json-view


    【解决方案1】:

    已在 grails-views v1.1.3 中解决。

    https://github.com/grails/grails-views/releases/tag/v1.1.3

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-24
      • 2016-06-28
      • 1970-01-01
      • 2020-05-07
      • 2015-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多