Grails JSON转换器未序列化嵌入的子对象
我将我的项目从Grails2.3.4升级到2.3.8,嵌入式JSON对象的转换停止工作 我使用MongoDB作为唯一的持久性 下面是我的代码结构Grails JSON转换器未序列化嵌入的子对象,grails,grails-2.0,Grails,Grails 2.0,我将我的项目从Grails2.3.4升级到2.3.8,嵌入式JSON对象的转换停止工作 我使用MongoDB作为唯一的持久性 下面是我的代码结构 // Post class class Post { String id String title String content List comments static embedded = ['comments'] static hasMany = [comments: Comment] }
// Post class
class Post {
String id
String title
String content
List comments
static embedded = ['comments']
static hasMany = [comments: Comment]
}
//Comments class
class Comment {
String name
String email
String website
String content
}
//code in controller
class PostController {
def show() {
def postInstance = Post.collection.findOne(title: id)
postInstance = postInstance as Post
log.info "Post comments with id {postInstance.comments.name}"
respond postInstance
}
}
//log details
INFO Post comments with id [Hussain1, Hussain2]
//JSON Response
{
"class": "com.Post",
"id": "5364be6703647a4cd37dd293",
"comments": [
{
"class": "com.Comment",
"id": null
},
{
"class": "com.Comment",
"id": null
}
],
"content": "Content",
"title": "This-is-a-title"
}
你知道为什么JSON对象中的子对象不能正常工作吗?Grails 2.3.4中的工作原理类似,你是从MongoDB而不是域实例渲染BSONObject,这是故意的吗?如果是这样,请检查您在Post文档集合中实际存储的数据。否则,请在处提交jira并附加一个重现问题的示例。Hi-Graeme我尝试了使用Post.findbytle(id)获取BSONObject和域实例的两种方法。两种情况下的结果相同,我将在JIRA中创建一个示例项目报告。Graeme,我已将JIRA与一个示例项目一起提交