java - 无法读取文档 : Expected type float, 整数或字符串

标签 java spring rest

我正在尝试发送放置请求,但收到以下错误,

    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());
    }
}

Controller :

@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);
    }

最佳答案

问题是我在更改后将 JsonSerializer 和 JsonDeSerializer 放在实体上而不是 DTO 上

关于java - 无法读取文档 : Expected type float, 整数或字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39038571/

相关文章:

java - 如何在 Matlab 中使用 java.nio?

java - 我想使用 servlet 创建一个登录页面

java - Zuul代理-如何根据请求路径将请求转发到服务

java - 带有注释的 Spring MVC 验证

java - 使用 token (Java) 保护 REST Web 服务

web-services - 为什么 Windows Phone 应用程序的 REST 服务中会出现 NotFound 错误?

java - getCurrentUser() 函数错误

java - JSF2 : commandLink without javascript

spring - Tomcat 7.0.47+ Websocket 故障转移

java - Hibernate更新对象的非引用字段