java - 将 JSON 映射到包含地图的自定义对象
问题描述
我有一个这样的 json,它嵌套在其中一个字段中 -
{
"templateid": "email_verified_template",
"templatevalues": {
"patient_name": "nprj09”,
"date": “Monday, 3rd May, 10:37:23 PM”,
},
"emailAddress": “nprj09@test.com”,
}
我创建了一个自定义类,
public class EmailTemplate implements Serializable {
private String templateid;
private Map<String,String> templatevalues;
private String emailAddress;
---
}
在我的服务类中,我正在读取 json 并将其映射到我的 EmailTemplate 类中,但映射失败。我可以在这里使用什么?
ObjectMapper mapper = new ObjectMapper();
try {
notificationVo = mapper.readValue(msg, EmailNotificationVO.class);
例外:
An Exception has occurred..com.fasterxml.jackson.databind.JsonMappingException: Illegal unquoted character ((CTRL-CHAR, code 13)): has to be escaped using backslash to be included in string value
at [Source: (String)"{
"templateid": "email_verified_template",
"templatevalues": {
"patient_name": "nprj09”,
"date": “Monday, 3rd May, 10:37:23 PM”
我尝试添加
mapper.configure(
JsonReadFeature.ALLOW_UNESCAPED_CONTROL_CHARS.mappedFeature(),
true
);
但这也不起作用。
解决方案
映射的代码很好。只需正确输入 JSON。
推荐阅读
- python - 未找到 Azure Devops 发布管道 Python 模块
- javascript - 在 RxJS 6 中取消订阅?
- vb.net - Visual Basic shell32.shell
- spring-cloud-dataflow - Spring Cloud 数据流浏览器控制台报错
- coq - 当您有多行定义归纳构造函数的操作时,这意味着什么?
- javascript - 简写 if-else 在 Javascript 中返回错误
- apache-kafka - Kafka 中的“__consumer_offsets”主题是什么
- node.js - Node.js 分号使用
- javascript - 单击后更改图像,但将其他选项卡重置为初始图像 javascript
- javascript - 如何在事件发生后使用 React 滚动到元素?