Grails/Jackson JSON序列化如何

Grails/Jackson JSON序列化如何,json,grails,serialization,jackson,Json,Grails,Serialization,Jackson,如何在Grails应用程序中“启用”Jackson序列化 在BuildConfig.groovy中,我添加了: compile 'com.fasterxml.jackson.core:jackson-core:2.5.3' compile 'com.fasterxml.jackson.core:jackson-annotations:2.5.3' 这就是所需要的全部吗?还是需要Config.groovy中的一些其他魔法 如何仅使用getter序列化属性 我想在生成的JSON中包含一个域类中“g

如何在Grails应用程序中“启用”Jackson序列化

在BuildConfig.groovy中,我添加了:

compile 'com.fasterxml.jackson.core:jackson-core:2.5.3'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.5.3'
这就是所需要的全部吗?还是需要Config.groovy中的一些其他魔法

如何仅使用getter序列化属性

我想在生成的JSON中包含一个域类中“get”方法的值。我尝试过这种变化:

@JsonAutoDetect(setterVisibility=JsonAutoDetect.Visibility.NONE)
class SportsAgent {
    String name
    String address
    String phone
    String email
    String state

    Client client

    @JsonProperty('clientName')
    String getClientName() {
        if (client) {
            client.name
        }
    }
}
这会序列化为JSON,但不包括“clientName”。我尝试的所有其他变体通常都会出现一些解析错误。我已经在Java中使用@JsonSerialize和@JsonDeserialize的旧版本Jackson中成功地实现了这一点,但是这些注释现在不存在了