2016-08-19 36 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; 

合併:

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轉換後

相關問題