当该@JsonProperty财产使用,它是什么用的? [英] When is the @JsonProperty property used and what is it used for?

查看:535
本文介绍了当该@JsonProperty财产使用,它是什么用的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这豆'国家':

public class State {

    private boolean isSet;

    @JsonProperty("isSet")
    public boolean isSet() {
        return isSet;
    }

    @JsonProperty("isSet")
    public void setSet(boolean isSet) {
        this.isSet = isSet;
    }

}

被发送使用ajax的'成功'回调线:

is sent over the wire using the ajax ' success' callback :

        success : function(response) {  
            if(response.State.isSet){   
                alert('success called successfully)
            }

在这里需要注释@JsonProperty?什么是使用它的优势在哪里? 我想我可以删除这个注释,而不会造成任何副作用。

Is the annotation @JsonProperty required here ? What is the advantage of using it ? I think I can remove this annotation without causing any side effects.

阅读关于这个annotion在 http://wiki.fasterxml.com/JacksonAnnotations 我不知道什么时候这是必需的使用?

Reading about this annotion on http://wiki.fasterxml.com/JacksonAnnotations I don't know when this is required to be used ?

推荐答案

下面是一个很好的例子。我用它来重命名变量,因为JSON是从.NET环境下性能开始与一个大写字母来了。

Here's a good example. I use it to rename the variable because the JSON is coming from a .Net environment where properties start with an upper-case letter.

public class Parameter {
  @JsonProperty("Name")
  public String name;
  @JsonProperty("Value")
  public String value; 
}

这正确分析/从JSON:

This correctly parses to/from the JSON:

"Parameter":{
  "Name":"Parameter-Name",
  "Value":"Parameter-Value"
}

这篇关于当该@JsonProperty财产使用,它是什么用的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆