我正在将对象转换为json。 首先将我的对象转换为地图。
对于所有属性,它的工作都很好,除了“ LocalDateTime”类型的属性之外。对于“ LocalDateTime”属性,我希望值应显示在单行中,例如: “ UpdatedTimestamp”:“ 2018-10-09T16:57:57.176”,
但是它显示为:
"UpdatedTimestamp": {
"dayOfYear": 326,
"dayOfWeek": "THURSDAY",
"month": "NOVEMBER",
"dayOfMonth": 22,
"year": 2018,
"monthValue": 11,
"hour": 1,
"minute": 14,
"second": 48,
"nano": 572000000,
"chronology": {
"id": "ISO",
"calendarType": "iso8601"
}
},
我当前的代码:
Gson gson = new Gson();
String json = gson.toJson(object.getMap());