- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我从一个项目向另一个项目发送数据。
我在 LinkedHashMap 中有我的数据。
当我发送时,我在 Json 中转换 map :objectMapper.writeValueAsString(visitToInsurer)
当我尝试将 json 值转换为映射时,我会这样做:
T getJsonMessage(byte[] body) throws IOException {
return objectMapper.readValue(body, resolveGenericType());
}
Class<T> resolveGenericType() {
Class<?>[] tClass = GenericTypeResolver.resolveTypeArguments(getClass(), SomeClass.class);
return (Class<T>) tClass[0];//here i get interface of Map
}
com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of java.util.LinkedHashMap (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value
('{"id":1,"id2":2,"bDate":"2020-04-04T16:22:45.032087","eDate":"9999-12-31T00:00","cDate":"2020-04-04T16:22:45.032087","use":"1","act":true,"in":0,"vDt":null,"vDt2":null,"dCheck":null,"vFlag":true,"nFlag":false,"vFlag2":false,"nFlag2":false,"uFlag":true,"rFlag":false,"dId":1,"it":1,"rId":1,"rCode":"1","iNum":"1","iAb":"OOO\"TEST-1 \"TEST\"","dId3":2,"dId4":2,"dName":"Test","vId5":null,"vId6":null,"pDt7":null,"pDt8":null,"vDt9":null,"vDt10":null,"wCnt":null,"dId8":null,"dId9":null,"dName10":null,"dName11":"Test","cReason":null,"vd12":null,"vId13":null,"vNum14":null,"vDate15":null,"act":null,"rLst":[{"id":1,"id2":2,"bDate":"2020-04-04T16:22:45.236460","eDate":"9999-12-31T00:00","cDate":"2020-04-04T16:22:45.236460","user":"1","vId":1,"vId2":1,"dId":2,"dId2":2,"dName":"TTT","pDt":null,"pDt2":null,"vDt":null,"vDt2":null,"cBegin":"2020-05-04T00:00:00","cEnd":"2020-05-05T00:00:00","cNum":"111","amount":0,"amount2":0,"prem":0,"f":0,"pen":0,"dId5":1,"dName6":"Test","aFlag":false,"rId":11,"rCode":"11","cNum":0,"dId7":1,"pId8":null,"pId9":null,"act":null}],"vCard":{"id":1,"id2":1,"bDate":"2020-04-04T16:22:45.032087","eDate":"9999-12-31T00:00","cDate":"2020-04-04T16:22:45.032087","user":"1","act":true,"invalid":0,"rId":1,"rCode":"1","iName":"TEST \"TEST \"TEST\"","iName2":"TEST\"TEST \"TEST\"","rNum":"1","in5":"1","k77":"1","og77":"11","rBegin":"2009-09-28T00:00:00","inDate":"2009-09-28T00:00:00","outDate":null,"phone":null,"localAddress":"TEST","email":null,"iStatus":"State","sCode":"1","iCode":"1","oCode":"1","cBegin5":"1900-01-01T00:00:00","pName":null,"pName2":null,"pReg":null,"action":null,"vList":[{"id":1,"id2":"1","cCode":"1","vId":1,"vId2":1,"bDate":"2020-04-04T16:22:45.032087","eDate":"9999-12-31T00:00","cDate":"2020-04-04T16:22:45.032087","user":"1","actual":true,"rId":1,"rCode":"1","came":"ТTEST","cPhone":null,"cP":"TEST","action":null}],"vList2":[]},"vList3":[{"id":1,"id2":1,"bDate":"2020-04-04T16:22:45.095369","eDate":"9999-12-31T00:00","cDate":"2020-04-04T16:22:45.095369","user":"1","actual":true,"vId":1,"vId":1,"tNum":"1","surname":"TEST","name":"TEST","pat":"TEST","pName2":"TEST","phone":null,"kId":1,"kId2":1,"vChecks":"TEST","nFlag":false,"vFlag":true,"nFlag2":false,"vFlag2":false,"action":null}],"vList5":[]}')
public class ProducerMsg {
private String body;
private Object objectBody;
}
最佳答案
Please refer below code
public class JsonToMapDemo {
public static void main(String[] args) {
String json = "{\"name\":\"Akshay\",\"age\":\"23\"}";
convertJsonToMap(json);
}
private static void convertJsonToMap(String jsonString) {
try {
Map<String, Object> personMap = new ObjectMapper().readValue(jsonString, Map.class);
System.out.println(personMap);
}
catch (JsonGenerationException e)
{
e.printStackTrace();
}
catch (JsonMappingException e)
{
e.printStackTrace();
} catch (JsonProcessingException e) {
e.printStackTrace();
}
code output
{name=Akshay, age=23}
关于java - com.fasterxml.jackson.databind.exc.MismatchedInputException : Cannot construct instance of `java.util.LinkedHashMap` ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61031589/
我有以下类(class) public class Cart { private final String id; public Cart(String id) { this.id =
我有一个 PSQL 表,其中一列包含 jsonb 数据: CREATE TABLE IF NOT EXISTS user ( user_name VARCHAR(255) NOT NULL,
我正在尝试读取我的 .json 文件。是一个 VehicleRepository 类。 "{\"vehicles\":[{\"id\":\"9467d079-4502-4dba-9d23-b8506d
我正在尝试制作一个 GUI (javaFX),并尝试读取 .JSON 文件,然后将其反序列化为对象。尽管我不断收到相同的错误:MismatchedInputException。我没有制作 Spring
我在 RestController 中定义了一个 API,它接受 json 请求。输入的 pojo 如下。 class A{ class List sharedModels; } SharedMode
使用 spring 配置将数据从 json 读取到 spring bean 中,它适用于简单类型,但在尝试读取数组时出现上述错误这是我的配置 @Bean Container container() t
我正在使用 Jackson ObjectMapper像这样的类: objectMapper.treeToValue(jsonNode, MyClass.class) 其中 jsonNode 是 Jso
我在 Spring Boot 应用程序中使用com.fasterxml.jackson.databind。当我向端点发送请求时,我收到以下异常: com.fasterxml.jackson.datab
我有多个 DTO 对象,它们都如下所示: @Getter @RequiredArgsConstructor public class SomeDTO { private final String
我尝试在LinkedHashMap测试用例中将JSON映射为kotlin。当我使用json将object转换为jackson-objectmapper时,出现以下问题,请帮我解决这个问题。 const
我正在尝试使用fasterxml将json回复解析为POJO。但问题是 json 回复包含嵌套对象,其中包含反斜杠,因此在通过 ObjectMapper 读取此值时,我收到 com.fasterxml
我在请求正文中发布带有转义字符的 json 字符串,并将其映射到 Controller 中的模型,但它抛出以下异常 json string : "{\"id\":\"1\",\"desc\":\"te
谁能帮我找出我在这里做错了什么。我必须解析下面的 XML 字符串 true A01222262 Bob NEWYORK_ADDRESS
我有一个简单的类 public class AuthenticationToken { public String token; public AuthenticationToken(
具有以下json片段: "Location": { "Address": "" }, 还有我的Pojo public class Address implements Serializable
我试图读取的yaml格式如下 - name: storage scm: git src: git+https://bitbucket.org/cer/linux_storage_jenkins
我在尝试通过 Swagger 发布请求时收到以下错误。当我通过 Postman 执行此操作时,效果很好。 我正在使用 springBootVersion = '2.1.0.RELEASE',swagg
我正在尝试发布用户组: public UserGroup createUserGroup(UserGroup userGroup) { ResponseEntity userGroupResp
我正在尝试运行以下 Junit 测试: @Test public void testObjectMapper() throws IOException { String json =
我有 2 个通过 REST 调用进行通信的微服务。我有一个名为 Consumer 的实体,它具有各种字段,包括 LocalDate。当我通过 REST 调用传递该实体时,出现以下异常 Json par
我是一名优秀的程序员,十分优秀!