问题
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