Java - Convert xml to JAVA Pojo classes including java annotations(Simplexml)

拜拜、爱过 提交于 2019-12-11 06:11:30

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/52307724/java-convert-xml-to-java-pojo-classes-including-java-annotationssimplexml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!