无法从json对象在dto中找到数据-分析错误ZoneDateTime

dba5bblo  于 2021-07-08  发布在  Java
关注(0)|答案(1)|浏览(305)

我正在尝试将json timestamp对象转换为java

我已经研究了如何将json字符串转换成java,但不确定我在寻找什么。如果json使用数组,我可以让它工作,但不幸的是,它没有使用这种方法。
json负载

{
  "type": "RFID-read",
  "event": {
    "id": "3892fec6-9246-4699-ba86-99ab1df369a9",
    "timestamp": "2020-11-19T15:01:11.391+0000",
    "deviceId": "FX9600FB2D21",
    "data": {
      "format": "epc",
      "id": "000000000000000000000115",
      "reads": 1,
      "rssi": -72,
      "antennaId": "1"
    }
  },
  "analytics": {
    "tenant": "73876942a20c12550f996b2152e5ca9e",
    "resourceId": "000000000000000000000115",
    "location": "FX9600FB2D21",
    "timestamp": "2020-11-19T15:01:11.391+0000",
    "meta": {
      "type": "inventory"
    }
  }
}

事件dto

@Data
@Builder(toBuilder = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ZebraEventReadsDto {

private String id;
private ZonedDateTime timestamp;
@NotNull
@Size(min = 1, max = 100)
private String deviceId;
private String format;
ZebraDataReadsDto data;

更新dto

@Data
@Builder(toBuilder = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ZebraLocationUpdateDto {

    private String type;
    ZebraEventReadsDto event;

    public static List<LocationUpdateDom> toDomainModel(ZebraLocationUpdateDto zebraLocationUpdateDto) {
        List<LocationUpdateDom> locationUpdateDomList = new ArrayList<>();

        locationUpdateDomList.add(LocationUpdateDom.builder()
                .deviceName(zebraLocationUpdateDto.zebraEventReadsDto.getDeviceId())
                .dateTime(zebraLocationUpdateDto.zebraEventReadsDto.getTimestamp())

                .tagId(zebraLocationUpdateDto.zebraEventReadsDto.data.getId())

                .latLng(Optional.empty())
                .build());

        return locationUpdateDomList;
    }

}
b91juud3

b91juud31#

为了解决解析错误,我在timestamp变量上方使用了以下注解。

@JSONFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"
private ZonedDateTime timestamp;

我现在可以退200好吗

相关问题