无法从START_ARRAY标记中反序列化java.lang.String的实例;

时间:2017-08-31 19:05:02

标签: java json spring postgresql

请帮我解决这个问题:

Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Can not deserialize instance of java.lang.String out of START_ARRAY token; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.String out of START_ARRAY token
 at [Source: java.io.PushbackInputStream@4010b719; line: 1, column: 31]

我发送以下JSON请求:

{"title": "Test", "category": ["2","4","3",1], "description": "Test", "username": ""}

“类别”列上发生错误。

我使用的是PostgreSQL数据库 我有以下模型:

 @Id
@Column(name = "ID")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "idea_seq")
@SequenceGenerator(name = "idea_seq", sequenceName = "idea_seq", allocationSize = 1)
private Integer id;

@Column(name = "TITLE", length = 100)
@NotNull
@Size(min = 1, max = 100)
private String title;

@Column(name = "CATEGORY", length = 10)
@NotNull
@Size(min = 1, max = 100)
private String[] category;

@Column(name = "DESCRIPTION", length = 1000)
@NotNull
@Size(min = 1, max = 1000)
private String description;

@Column(name = "USERNAME", length = 100)
@NotNull
@Size(min = 1, max = 100)
private String username;

我会对任何帮助感到高兴。我已经有几天这个bug了。

1 个答案:

答案 0 :(得分:0)

您的类别JSON包含数字

&#34;类别&#34;:[&#34; 2&#34;,&#34; 4&#34;,&#34; 3&#34;, 1 ] < / p>

这需要引用。