2016-08-19 2 views
1

Я пытаюсь отправить поставить запрос и я получаю следующее сообщение об ошибке,Не удалось прочитать документ: ожидаемый тип с плавающей точкой, целое число, или строку

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; 

Merge:

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

'ZonedDateTimeConverter': это самостоятельно класс (пожалуйста, покажите код) или он поступает из сторонней библиотеки? –

+0

@ArnaudDenoyelle Добавил его. –

+0

Проблема в контроллере останова. Вы можете это показать? – davidxxx

ответ

0

Проблема заключалась в том, что я поставил JsonSerializer и JsonDeSerializer на сущности не на DTO после изменения

Смежные вопросы