java - 杰克逊序列化通用但不反序列化
问题描述
我怎样才能使这项工作?我看看其他问题,但我无法弄清楚如何。其实我对杰克逊了解不多。也许“龙目岛”是问题的根源。先感谢您。
@Data class A{String b;}
@Data class B<T>{ T c; }
A a1 = new A();
a1.setB("sa");
B<A> s = new B<A>();
s.c = a1;
ObjectMapper objectMapper = new ObjectMapper();
String sj = objectMapper.writeValueAsString(s);
System.out.println(sj); // {"c":{"b":"sa"}}
B<A> ba = objectMapper.readerFor(new TypeReference<B<A>>() {
})
.readValue(sj); // this is not working
给出这个错误:
com.fasterxml.jackson.databind.JsonMappingException: Cannot deserialize
EmbeddedTest$1B (of type local/anonymous) as a Bean.
解决方案
推荐阅读
- load-balancing - 我需要更多资源还是需要负载均衡器?
- sql - 如何在子字符串 SQL 中搜索特殊字符
- asp.net - 为 ASP/ASPX 文件上传设置什么内容类型?
- android - 在 ListView 中添加 TextView 跑马灯效果失败
- mysql - 从 dbeaver 连接到 MySQL 服务器给出检查“useSSL”是否设置为“true”
- r - R 在尝试使用 registerDoParallel 注册集群后卡住了
- python - python中具有o(n)顺序的大列表的快速列表减法
- react-native - 无法解析模块`@expo/vector-icons/fonts/Ionicons.ttf`
- c - printf 函数在输入之前不起作用
- php - 如何将 DI 容器注入控制器?