【发布时间】:2017-03-14 18:03:52
【问题描述】:
我正在尝试使用 POST 方法保存一个实体数组,并传递一个用于休息资源的数组,但我有一个错误:
org.springframework.http.converter.HttpMessageNotReadableException: Could not read document: Can not deserialize instance of br.com.servtech.almox.model.Item out of START_ARRAY token
at [Source: org.apache.catalina.connector.CoyoteInputStream@2af1e451; line: 1, column: 1]; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of br.com.servtech.almox.model.Item out of START_ARRAY token
at [Source: org.apache.catalina.connector.CoyoteInputStream@2af1e451; line: 1, column: 1]
at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readJavaType(AbstractJackson2HttpMessageConverter.java:228) ~[spring-web-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readInternal(AbstractJackson2HttpMessageConverter.java:205) ~[spring-web-4.3.3.RELEASE.jar:4.3.3.RELEASE]
什么时候给一个对象发送数据,数据保存得很好!
我的实体:
@Entity
public class Item implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Basic
private String name;
@Basic
private Integer quantity;
@Basic
private Double cash;
@ManyToOne
private Requirement requirement;
//getters and setters
}
我的仓库:
@RepositoryRestResource
@CrossOrigin
public interface ItemDAO extends CrudRepository<Item, Long> {
}
数据:
[{
"name": "A1",
"quantity": 3,
"cash": 5.80
}, {
"name": "B2",
"quantity": 3,
"cash": 5.80
}]
我尝试使用 Content-Type 应用程序/json 并与 text/uri-list 一起使用。 怎么了?我再做一些设置?
【问题讨论】:
-
请同时发布您的控制器方法和请求调用附带的关联值对象..
-
他正在使用 Spring Data Rest,他已经这样做了。
-
我已请求该功能,请投票:jira.spring.io/browse/DATAREST-1285
标签: java spring spring-boot spring-data-rest