我正在尝试发送put请求,并收到以下错误,
Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: Could not read document: Expected type float, integer, or string.
nested exception is com.fasterxml.jackson.databind.JsonMappingException: Expected type float, integer, or string.
实体中的值:(转换器的类型为:AttributeConverter,尝试删除它仍然不起作用)
@Convert(converter = ZonedDateTimeConverter.class)
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
@Column(name = "LAST_MODIFIED")
protected ZonedDateTime lastModified;
合并:
this.entityManager.merge(entity);
this.entityManager.flush();
使用:
jackson-datatype-jsr310
我尝试使用JsonSerializer和JsonDeSerializer但结果是一样的。
转换器:
@Converter(autoApply = true)
public class ZonedDateTimeConverter implements AttributeConverter<ZonedDateTime, Date> {
@Override
public Date convertToDatabaseColumn(final ZonedDateTime attribute) {
if(attribute == null){
return null;
}
return Date.from(attribute.toInstant());
}
@Override
public ZonedDateTime convertToEntityAttribute(final Date dbData) {
if(dbData == null) {
return null;
}
return ZonedDateTime.ofInstant(dbData.toInstant(), ZoneId.systemDefault());
}
}
控制器:
@Override
public ResponseEntity update(@RequestBody final DTO dto) {
boolean updated = this.service.update(dto);
if(updated){
return new ResponseEntity(HttpStatus.OK);
}
return new ResponseEntity(HttpStatus.NO_CONTENT);
}
答案 0 :(得分:0)
问题是我在更改后将JsonSerializer和JsonDeSerializer放在DTO上的实体上