java - How to Covert a @XmlType to Json string?
问题描述
I want to convert a an entity which is @XmlType to a Json string in java. I searched for such question but all I have found is to convert a XML string to Json string .
解决方案
I would recommend to use the Jackson library for this job. This works with any Java class as long it's structure is somehow compatible to JSON:
ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
String json = ow.writeValueAsString(object);
The "withDefaultPrettyPrinter" part is optional.
推荐阅读
- python - 如何使用 Torch 框架从训练日志中绘制损失图
- php - 在 Craft 3 中从模板传递到自定义模板标签时,如何遍历标签字段?
- python - 使用 Oanda 问题实现外汇交易算法
- ttl - 如何在 clickhouse 表上使用 TTL?
- python - 如何在 C API 中创建 Python 字节对象
- javascript - 有问题的滑块 - 如何让我的滑块很好地适合里面的组件?
- c - 链表的这个空闲列表递归函数是做什么的?
- css - Flexbox 网格:如何并排显示 3 个项目,但垂直位置不同
- javascript - 重写jQuery函数来处理同一页面上的两个多级下拉菜单
- javascript - 使用 css 和 javascript 旋转立方体时保持固定轴