1、如何安装GsonFormat插件
步骤:Setting-->Plugins,如果这里没有,就点击Browse repositories搜索
![22da0003ea65992273308dfdb2d7247a.png](https://img-blog.csdnimg.cn/img_convert/22da0003ea65992273308dfdb2d7247a.png)
搜索GsonFormat
安装好以后,重启IDEA。
我原来将json转为实体bean,是通过个一个网站(http://www.bejson.com/json2javapojo/new/)。我在《如何封装第三方API(如今日头条)为后期维护和开发带来方便》这篇文章里面提到过,有兴趣的可以看下。我演示个简单的。
![11df4f81d8c49018232ff6f82447b644.png](https://img-blog.csdnimg.cn/img_convert/11df4f81d8c49018232ff6f82447b644.png)
json转为bean
但是这种还是相对于GsonFormat还是有点麻烦,我说下IDEA中如何使用这个插件。创建一个实体,并命名为Student
![721b7e2af3d5a22c4d76318adb0c4e15.png](https://img-blog.csdnimg.cn/img_convert/721b7e2af3d5a22c4d76318adb0c4e15.png)
创建Student实体
快捷键Alt+s,会弹出一个框出来,把json放到这个框里
![2b4a02df71877c31c13d27968bcc3a09.png](https://img-blog.csdnimg.cn/img_convert/2b4a02df71877c31c13d27968bcc3a09.png)
把json放到框里
这里不满意类型的定义,比如id不应该为int类型,而应该是long类型,还可以修改
![46dbbc6510191245922d29ce3a259240.png](https://img-blog.csdnimg.cn/img_convert/46dbbc6510191245922d29ce3a259240.png)
修改类型
点击OK生成
![33e0422bea30a375f11d0c2ed10c7124.png](https://img-blog.csdnimg.cn/img_convert/33e0422bea30a375f11d0c2ed10c7124.png)
出现SerializedName
如何将这个东西去掉,弹出框中有Setting,点击Setting,把use serializedNamed的勾去掉。
![8ccfa451ff469cf1b7ebcf7004772f80.png](https://img-blog.csdnimg.cn/img_convert/8ccfa451ff469cf1b7ebcf7004772f80.png)
把use serializedNamed的勾去掉
再次生成就好了。
![8e826eba0f25f1939328da01919fba7e.png](https://img-blog.csdnimg.cn/img_convert/8e826eba0f25f1939328da01919fba7e.png)
总结:个人认为这是个很好的插件,用起来很方便。