Java Spring框架序列化不适用于键带有下划线的JSON
我正在使用以下版本的spring框架:Java Spring框架序列化不适用于键带有下划线的JSON,java,spring,serialization,deserialization,Java,Spring,Serialization,Deserialization,我正在使用以下版本的spring框架: <org.springframework.version>3.2.4.RELEASE</org.springframework.version> 请注意,其中一个键有一个下划线(temp_min)。 我的模型如下: private double temp_min; public double getTempMin() { return this.temp_min; } public void setTempMi
<org.springframework.version>3.2.4.RELEASE</org.springframework.version>
请注意,其中一个键有一个下划线(temp_min)。
我的模型如下:
private double temp_min;
public double getTempMin() {
return this.temp_min;
}
public void setTempMin(double temp_min) {
this.temp_min = temp_min;
}
private double temp;
public double getTemp() {
return this.temp;
}
public void setTemp(double temp) {
this.temp = temp;
}
温度设置正确,但未设置“最低温度”
我在getter、setter和变量声明上方尝试了@JsonProperty(“temp_min”)
我使用的是spring框架的默认序列化。
有人能帮我解决这个问题吗?您可以在变量上添加注释
@JsonProperty(temp_min)
private double temp_min;
还有附加类名
@JsonIgnoreProperties(ignoreUnknown = true)
您确实希望对变量进行注释, 但您也希望正确地对其进行注释 仅使用以下解决方案之一: 1) 用@JsonProperty注释私有变量
@JsonProperty("temp_min")
private double temp_min
2) 注释setter(和getter,如果需要)
3) 使用@JsonProperty注释setter(和getter,如果需要)
@JsonProperty("temp_min")
public void setTempMin(...)
{
...
}
@JsonProperty("temp_min")
public double getTempMin()
{
...
}
我在getter、setter和变量声明上面尝试了@JsonProperty(“temp_min”)
@JsonSetter("temp_min")
public void setTempMin(...)
{
...
}
@JsonGetter("temp_min")
public double getTempMin()
{
...
}
@JsonProperty("temp_min")
public void setTempMin(...)
{
...
}
@JsonProperty("temp_min")
public double getTempMin()
{
...
}