- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我需要将 ajax 请求作为 json 传递给我的休息服务。我的模型类是
@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
}
休息 Controller
@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();
}
});
我从ajax调用传递的json数据就像
{"title":"dhfg","tags":["Interactive","Online"],"documents":[],"links":[]}
如何从 json 传递标签数组?我是 Java 新手
错误详细信息
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;
解决了我的问题:)
关于java - 无法从 START_ARRAY token 中读取文档 : Can not deserialize instance of java. lang.String,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46386847/
我需要像这样反序列化 Json: { "arrayObj1":[ { "type":"t1", "value":[
我正在编写一个使用 robospice、retrofit 和 Jackson 2.4.X 的 Android 应用程序, 这是我试图反序列化从休息服务返回的 json。返回的“data”数组中的元素是
我在从我们从 EXTJS 存储发送的 JSON 文件中反序列化多个任务(数据)时遇到问题。在更新单个任务时它的工作正常。但是当我们更新多个任务时,它会显示 org.codehaus.jackson.m
我有两个对象,一个是 Dashboard,第二个是 Room 我有一个 json,看起来像这样 { "hotel_id":"1", "hotel_room":"200", "hotel_prope
我在尝试解析之前使用 Jackson 生成的一些 JSON 时收到此错误。我像这样生成 JSON String ret = ""; ret = mapper.writeValueAsString(me
我需要向网络服务发送一个发布请求,但它返回以下异常 java.io.IOException: Server returned HTTP response code: 500 for URL doma
谁能说我哪里做错了。我有这样的 json [{"name":"foo","slug":"foo2","locales":["foo3"],"hostname":"foo4","region_tag":
我是 Spring Boot 和 API 的新手,我正在开发一个项目,尽管我的 Spring Boot 应用程序与 MySQL 数据库连接,但我需要从公共(public) API 获取数据并将其存储到
我正在尝试使用 jackson api 解析 json,并包含以下详细信息。但我收到错误。请查找以下代码和堆栈跟踪详细信息。 JSON [{"id":1001,"cyPerReffe":1200,"d
我正在尝试将我的 json 请求解析为我的模型。我不知道,这段代码有什么问题。 json 的语法看起来是正确的,Java 模型上的注释也是如此。我不知道为什么我会收到如下错误: Caused by:
我有一个 SpringBoot 应用程序。使用此配置文件: @Configuration public class ApplicationConfig { @Bean public R
我有一个带有restTemplate调用的方法,如下所示: restTemplate.getForObject(apiUrl ,Someclass.class); Someclass.class: @
我正在尝试通过 jQuery AJAX 将对象数组发送到 Spring Controller 。这是 JavaScript 代码: var data = new Array(); $.
我在这个问题上遇到了同样的问题,很高兴看到这个问题已经有了解决方案。但我无法在我的代码中实现它。 ( Cannot deserialize instance of object out of STAR
我正在尝试为我的索引更新文档,并在通过 Postman 更新 API 脚本时收到以下错误 { "error": { "root_cause": [ {
直接开始... 我有一个返回字符串的方法(请参阅下面的示例字符串) - 本质上,我向 URL 发出 HTTP GET 请求,响应是下面的字符串... { "total": 30, "rows"
我有一个像这样的json: { "games": [ { "id": "mhhlhlmlezgwniokgawxloi7mi", "from": "42
我知道 stackoverflow 上有一些关于这个问题的问题。但我花了几个小时试图解决这个错误,但没有成功。 我使用 mysql 数据库来存储值。 我不断收到来自com.example.spring
JSON 片段如下: "text": {"paragraph": [ "For use in manufacturing only.",
我必须从 servlet 中收到的 JSON 字符串创建 Java 对象下面是 JSON [{"name":"name","value":"Shital"},{"name":"email","valu
我是一名优秀的程序员,十分优秀!