1
我試圖讓我的服務器解析以下JSON消費OffsetDateTime:澤西
{"hardwareId":1,"registerTime":"2017-02-14T03:42:11.482Z","sensorId":1,"temperature":23.6}
的registerTime
屬性必須被解析到一個OffsetDateTime
實例:
@XmlRootElement
public class TemperatureRegister {
private int m_hardwareId;
private int m_sensorId;
private OffsetDateTime m_registerTime;
private double m_temperature;
public TemperatureRegister() {
}
public TemperatureRegister(OffsetDateTime p_registerTime, double p_temperature,
int p_hardwareId, int p_sensorId) {
if (p_registerTime == null) {
this.m_registerTime = OffsetDateTime.now(ZoneOffset.UTC);
}
this.m_registerTime = p_registerTime;
this.m_temperature = p_temperature;
this.m_hardwareId = p_hardwareId;
this.m_sensorId = p_sensorId;
}
...
}
那怎麼我的資源的方法定義:
@POST
@Path("/insert")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public TemperatureRegister addOne(TemperatureRegister p_register) {
m_mongoConnector.InsertOne(p_register);
return p_register;
}
出於某種原因,在該方法上述情況,p_register
參數始終是這樣的:
TemperatureRegister [m_hardwareId=1, m_sensorId=1, m_registerTime=null, m_temperature=23.6]
它正確地映射的一切,但registerTime
這是OffsetDateTime
。它總是null
。爲什麼這是唯一有問題的價值?
我做錯了什麼?它是否需要一些特殊的配置來處理OffsetDateTime?
LIFE SAVIOR !!!!!它完美無缺地工作! –
@filscapo如果我的答案解決了您的問題,請考慮通過點擊我的答案旁邊的綠色勾號來接受它:) –
OH! tks記住我=] –