Groovy Spring Data Mongo:使用Jackson注释映射对象

Groovy Spring Data Mongo:使用Jackson注释映射对象,groovy,jackson,spring-data-mongodb,Groovy,Jackson,Spring Data Mongodb,我使用SpringDataMongo(1.3.3)作为访问Mongo的机制。 我的域对象是用Groovy编写的,我使用Jackson注释来定义属性和名称: @JsonProperty('is_author') boolean author = false @JsonProperty('author_info') AuthorInfo authorInfo 当我将一个域对象持久化到Mongo时,会忽略JsonProperty注释,并使用标准对象的字段名持久化该字段。 通过挖掘Spring数据Mo

我使用SpringDataMongo(1.3.3)作为访问Mongo的机制。 我的域对象是用Groovy编写的,我使用Jackson注释来定义属性和名称:

@JsonProperty('is_author')
boolean author = false
@JsonProperty('author_info')
AuthorInfo authorInfo
当我将一个域对象持久化到Mongo时,会忽略JsonProperty注释,并使用标准对象的字段名持久化该字段。 通过挖掘Spring数据Mongo,我发现库需要一个
@Field
注释来修改Mongo中实际字段的名称


有没有办法只使用Jackson注释而不是使用两个注释来获得相同的结果。也许是MappingMongoConverter的“定制”版本?

因为我的应用程序在Groovy中,所以我使用了新的
@AnnotationCollector
AST转换()来“合并”Jackson和Spring数据Mongo注释。下面是它的样子:简单而有效

package com.someapp
import com.fasterxml.jackson.annotation.JsonProperty 
import groovy.transform.AnnotationCollector 
import org.springframework.data.mongodb.core.mapping.Field 
@AnnotationCollector([Field, JsonProperty]) 
public @interface JsonMongoProperty {}
下面是它的使用方法:

   @JsonMongoProperty('is_author')
   boolean author = false
   @JsonMongoProperty('author_info')
   AuthorInfo authorInfo

如果您使用的是Groovy 2.1+,是否可以使用AnnotationCollector?我就是这么做的!我本来想更新问题的,但你更快了。谢谢呵呵,你做了所有的工作!;-)也许把你所做的作为这个问题的答案?我知道我会投票支持它;-)