- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Jackson 读取从 Mailchimp 的 Mandrill API 返回的 JSON 响应。对于 API 响应来说,该响应有点不传统,因为它包含方括号内的 Handlebars (对象列表)。围绕此错误的其他堆栈溢出讨论与不在列表中的 API 响应有关。
[
{
"email": "gideongrossman@gmail.com",
"status": "sent",
"_id": "6c6afbd3702f4fdea8de690c284f5898",
"reject_reason": null
}
]
我收到此错误...
2019-07-06 22:41:47.916 DESKTOP-2AB6RK0 core.RestClient 131222 ERROR com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `core.user.MandrillWrapper$TemplatedEmailResponse` out of START_ARRAY token
定义此响应对象的正确方法是什么?
我尝试使用以下类型定义响应。没有一个起作用。
public static class TemplatedEmailResponse {
public LinkedHashMap<String, String>[] response;
}
public static class TemplatedEmailResponse {
public ArrayList<LinkedHashMap<String, String>> response;
}
@milchalk...我如何按照我当前调用 API 和处理响应的方式使用您的对象映射器建议?
TemplatedEmailResponseList ret = getClient("messages/send-template.json").post(mandrillPayload,
TemplatedEmailResponseList.class);
哪里
public <T> T post(Object payload, Class<T> responseType) {
try {
Entity<Object> entity = Entity.entity(payload, MediaType.APPLICATION_JSON);
T t = client.target(url).request(MediaType.APPLICATION_JSON).post(entity, responseType);
return t;
} catch (Throwable t) {
logError(t);
throw t;
} finally {
client.close();
}
}
最佳答案
你可以直接将此json反序列化为List
您的 Pojo 类。
给定模型类:
public class TemplatedEmailResponse {
private String email;
private String status;
private String _id;
private String reject_reason;
//getters setters
}
您可以使用 List<TemplatedEmailResponse>
的 TypeReference 反序列化此 json :
ObjectMapper mapper = new ObjectMapper();
TypeReference<List<TemplatedEmailResponse>> typeRef = new TypeReference<List<TemplatedEmailResponse>>() {};
List<TemplatedEmailResponse> list = mapper.readValue(json, typeRef);
哪里json
在本例中,变量表示 json 字符串。
关于java - 使用 Jackson 反序列化对象 json 对象列表 - 无法从 start_array token 中反序列化实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56919694/
我需要像这样反序列化 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
我是一名优秀的程序员,十分优秀!