Map<String, Object>转Object,Object转 Map<String, Object>
时间: 2023-11-11 19:59:33 浏览: 42
java 读取csv 并转为Map<String,Object>
将Map<String, Object>转换为Object:
```
Map<String, Object> map = new HashMap<>();
Object object = map;
```
将Object转换为Map<String, Object>:
```
Object object = new Object();
Map<String, Object> map = new ObjectMapper().convertValue(object, Map.class);
```
需要注意的是,这里使用了Jackson库中的ObjectMapper对象进行转换,所以需要先引入Jackson库。
阅读全文