Java - 将 xml 转换为 JAVA Pojo 类,包括 Java 注释(Simplexml) [英] Java - Convert xml to JAVA Pojo classes including java annotations(Simplexml)

查看:55
本文介绍了Java - 将 xml 转换为 JAVA Pojo 类,包括 Java 注释(Simplexml)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个使用 XML 作为 API 请求和响应正文的应用程序.为了使用改造来获取和解析它,我使用 SimpleXml 作为改造的转换器.但是为了为相应的XML创建pojo类,我在网上找不到任何类似于jsonchema2pojo的方法.

而且由于项目中涉及的 XML 非常庞大,手动创建 POJO 类非常耗时.

我将此问题作为常见问题解答发布,因为我自己很难找到简单的解决方案.

解决方案

Android Studio(也称为 IntelliJ IDEA)有一个名为 POJO Generator 的插件.您还可以在

我希望你觉得这很有用.

I am developing an application which uses XML as API request and response body. To fetch and parse this using retrofit, i have used SimpleXml as the converter for retrofit. But in order to create pojo classes for the corresponding XML, i could not find any online methods similar to jsonchema2pojo.

And since the XML involved in the project is huge in size, it is very time consuming to create POJO classes manually.

I am posting this question as an FAQ, since i had some trouble finding an easy solution to do this myself.

解决方案

There is a plugin for Android Studio(also IntelliJ IDEA) called POJO Generator. You can also find the plugin at this link.

After installation this plugin will be in the toolbar(invisible by default). To show the toolbar try View->Toolbar

Click on the plugin's icon and paste the XML in the box and select a destination. It will generate Pojo classes based on the XML with annotations(SimpleXML). Rest of the process(retrofit client creation, and API invocation) remains same.

I hope you find this useful.

这篇关于Java - 将 xml 转换为 JAVA Pojo 类,包括 Java 注释(Simplexml)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆