Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

The date is one day less when Jackson returns JSON

Shulou Source: shulou.com Published: 2022-06-03 07:18:10 09月23日 Update

After testing, it is found that when an object is converted to JSON, the value returned by the date type is always 1 less than the value in the database.

For example, if the date of the database is 2017-12-12, it will become 2017-12-1 when it is transferred to JSON. Solution 1:

Use @ JsonFormat (pattern= "yyyy-MM-dd", timezone= "GMT+8") br/ > solution 1 in the get method of the object POJO:

Use @ JsonFormat (pattern= "yyyy-MM-dd", timezone= "GMT+8") in the get method of the object POJO

/ * timeZone= "GMT+8" plus time zone * /

@ JsonFormat (pattern = "yyyy-MM-dd", timezone= "GMT+8")

Public Date getShenqrq () {

Return shenqrq

}

Public void setShenqrq (Date shenqrq) {

This.shenqrq = shenqrq

}

Solution 2:

NON_NULL

Tags: Method object date data database time zone type now test Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Shulou Information MariaDB Huawei Apple