@Entity
@Table(name = "messageslist")
public class MessageList {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Integer id;
public String title;
public String tags;
public String documents;
public String links;
//Then getters and setters
}
@RequestMapping(value = "/AddPost", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<MessageList> addPost(@RequestBody @Valid MessageList messageList, BindingResult bindingResult,
UriComponentsBuilder ucBuilder) {
BindingErrorsResponse errors = new BindingErrorsResponse();
HttpHeaders headers = new HttpHeaders();
if (bindingResult.hasErrors() || (messageList == null)) {
errors.addAllErrors(bindingResult);
headers.add("errors", errors.toJSON());
return new ResponseEntity<MessageList>(headers, HttpStatus.BAD_REQUEST);
}
this.taskManagerService.savePost(messageList);
headers.setLocation(ucBuilder.path("/api/TS/{id}").buildAndExpand(messageList.getId()).toUri());
return new ResponseEntity<MessageList>(messageList, headers, HttpStatus.CREATED);
}
var post = JSON.stringify({
title : title,
tags : tags,
documents : documents,
links : links
});
var url = "http://localhost:8080/TS/AddPost";
$.ajax({
type : 'POST',
url : url,
contentType : 'application/json; charset=utf-8',
data : post,
dataType : 'json',
success : function(data) {
onComplete();
}
});
{"title":"dhfg","tags":["Interactive","Online"],"documents":[],"links":[]}
2017-09-24 01:40:31.978 WARN 9600 --- [nio-8081-exec-1] .w.s.m.s.DefaultHandlerExceptionResolver : Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: Could not read document: Can not deserialize instance of java.lang.String out of START_ARRAY token
at [Source: java.io.PushbackInputStream@459b29e9; line: 1, column: 24] (through reference chain: org.fs.spring.tm.model.MessageList["tags"]); 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@459b29e9; line: 1, column: 24] (through reference chain: org.fs.spring.tm.model.MessageList["tags"])
我将模型类中标记的数据类型从
public String tags;
到
public ArrayList<String> tags;
解决了我的问题:)
下面提到的是JSON字符串ResultString: 我想将相同的内容转换为A类的对象: B类代码为: 但是获取异常: JSONMappingException:无法从START_ARRAY标记反序列化java.util.LinkedHashMap实例
给定以下JSON文件: 我试图使用Jackson对象映射器访问JSON文件中的值。具体如下:
我想从angular 8前端向spring boot API发送一个JSON对象。我是这些框架的新手,我有点迷茫。 错误: “无法将的实例从START_OBJECT标记反序列化到[源:(String)”{“coordines”:[{“lat”:76.00542202728906,“lng”:-71.76493508359451},{“lat”:62.96921913888247,“lng”:-11
下面是POJO类: 主要功能如下: