Android 改型在使用JACKSON解析JSON时返回零
改装正在为某些类型的JSON变量返回零Android 改型在使用JACKSON解析JSON时返回零,android,json,jackson,retrofit,Android,Json,Jackson,Retrofit,改装正在为某些类型的JSON变量返回零 @JsonIgnoreProperties(ignoreUnknown = true) public class Temperature implements Parcelable { @JsonProperty("day") public float dayAvg; @JsonProperty("min") public float minTemp; @JsonProperty("max") public float maxTemp; @Json
@JsonIgnoreProperties(ignoreUnknown = true)
public class Temperature implements Parcelable {
@JsonProperty("day")
public float dayAvg;
@JsonProperty("min")
public float minTemp;
@JsonProperty("max")
public float maxTemp;
@JsonProperty("night")
public float nightTemp;
@JsonProperty("eve")
public float eveningTemp;
@JsonProperty("morn")
public float morningTemp;
public Temperature(){
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeFloat(this.dayAvg);
dest.writeFloat(this.minTemp);
dest.writeFloat(this.maxTemp);
dest.writeFloat(this.nightTemp);
dest.writeFloat(this.eveningTemp);
dest.writeFloat(this.morningTemp);
}
private Temperature(Parcel in) {
this.dayAvg = in.readFloat();
this.minTemp = in.readFloat();
this.maxTemp = in.readFloat();
this.nightTemp = in.readFloat();
this.eveningTemp = in.readFloat();
this.morningTemp = in.readFloat();
}
public static final Parcelable.Creator<Temperature> CREATOR = new Parcelable.Creator<Temperature>() {
public Temperature createFromParcel(Parcel source) {
return new Temperature(source);
}
public Temperature[] newArray(int size) {
return new Temperature[size];
}
};
@JsonIgnoreProperties(ignoreUnknown=true)
公共类温度实现可包裹{
@JsonProperty(“日”)
公共浮动日平均值;
@JsonProperty(“min”)
公共交通管理计划;
@JsonProperty(“最大值”)
公共浮动maxTemp;
@JsonProperty(“夜晚”)
公共浮动夜间温度;
@JsonProperty(“eve”)
晚上公共浮子;
@JsonProperty(“上午”)
公众浮标晨温;
公众温度(){
}
@凌驾
公共int描述内容(){
返回0;
}
@凌驾
公共无效写入包裹(包裹目的地,内部标志){
dest.writeFloat(this.dayAvg);
dest.writeFloat(this.minTemp);
dest.writeFloat(this.maxTemp);
dest.writeFloat(this.nightTemp);
dest.writeFloat(this.eveningTemp);
dest.writeFloat(this.morningTemp);
}
私人温度(包裹内){
this.dayAvg=in.readFloat();
this.minTemp=in.readFloat();
this.maxTemp=in.readFloat();
this.nightTemp=in.readFloat();
this.eveningTemp=in.readFloat();
this.morningTemp=in.readFloat();
}
public static final Parcelable.Creator=新建Parcelable.Creator(){
公共温度createFromParcel(地块源){
返回新的温度(源);
}
公共温度[]新阵列(整数大小){
返回新温度[尺寸];
}
};
}
问题是,当使用改装时,
maxTemp
和minTemp
将为零。但如果我直接使用Jackson。我得到了maxTemp
和minTemp
的正确值问题在于@JsonProperty
。对于此注释,我们还需要使用@SerializedName
注释 jackson with Reformation?@njzk2是。Reformation使用GSON或jackson解析JSON.ok。但是,SerializedName
是一个gson注释,afaik