Java - Convert xml to JAVA Pojo classes including

2019-07-26 16:16发布

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条回答
你好瞎i
2楼-- · 2019-07-26 16:49

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.

enter image description here

I hope you find this useful.

查看更多
登录 后发表回答