java- 使用LocalDateTime报错

  • Post author:
  • Post category:java


在接口传入含有LocalTime类型属性对象的时候,反序列化失败报错:

message:JSON parse error: Can not deserialize value of type java.time.LocalDateTime from String “2019-12-12 11:25:07”: Text ‘2019-12-12 11:25:07’ could not be parsed at index 10; nested exception is com.fasterxml.jackson.databind.exc.

原来是要对时间的格式做一些说明:

	@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
	private LocalDateTime appointmentTime;

或者使用LocalDateTime的序列化反序列化方法:

    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    private LocalDateTime createTime;



版权声明:本文为sinat_26671533原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。