The Gsonformat plug-in is primarily used to parse a string of jsonobject format into entities using the Gson library, which speeds up development progress, makes it easy to use, and is highly efficient.
Plugin Address: Https://plugins.jetbrains.com/idea/plugin/7654-gsonformat
This tutorial is mainly about learning how IntelliJ idea can parse a string of jsonobject format into an entity through the Gsonformat plugin.
Generally speaking
Idea plug-in installation is very simple, for many plug-ins, as long as you know the name of the plug-in can be directly installed in the.
File->settings->plugins-> find the required plug-in->install
Or
File->settings->plugins->install plug from disk-> Select Download Good plugin installation
The general plugin will take effect if you restart idea after installation.
Detailed installation text below:
First into setting, and then by searching for plugins
Then the plugin bar searches for Gsonformat.
Installation can be done.
After installation, you need to restart idea.
Through JSON
123456789 |
{ "Animals":{ "Dog":[ { "name" : "Rufus" , "breed" : "Labrador" , "Count" :< Span class= "CRAYON-CN" >1, "Twofeet" :false} {"name": "Marty","breed":"Whippet","Count":1," Twofeet ":false} ], "Cat":{"name":"Matilda"} }} |
Custom JavaBean (no content, just an empty class)
Copy the JSON you want to parse
Then Alt+insert pop up the following interface or use the shortcut key Alt+s
Bring up the plugin via shortcut keys
Formatting JSON
can set
OK to generate the entity class
Configure birth fame
Generated as follows:
1 Packagecom.yuanding.entity;2 3 Importjava.util.List;4 5 /**6 * Created by DIYVC on 2017/3/13.7 */8 Public classTestClass {9 Ten One /** A * Animals: {"dog": [{"Name": "Rufus", "Breed": "Labrador", "Count": 1, "Twofeet": false},{"name": "Marty", "Breed": " Whippet "," Count ": 1," Twofeet ": false}]," cat ": {" name ":" Matilda "}} - */ - the PrivateAnimalsbean Animals; - - PublicAnimalsbean getanimals () { - returnanimals; + } - + Public voidsetanimals (Animalsbean animals) { A This. Animals =animals; at } - - Public Static classAnimalsbean { - /** - * Dog: [{"Name": "Rufus", "Breed": "Labrador", "Count": 1, "Twofeet": false},{"name": "Marty", "Breed": "Whippet", "Cou" NT ": 1," Twofeet ": false}] - * Cat: {"name": "Matilda"} in */ - to PrivateCatbean cat; + PrivateList<dogbean>Dog; - the PublicCatbean Getcat () { * returnCat; $ }Panax Notoginseng - Public voidSetcat (Catbean cat) { the This. cat =Cat; + } A the PublicList<dogbean>Getdog () { + returnDog; - } $ $ Public voidSetdog (list<dogbean>dog) { - This. Dog =Dog; - } the - Public Static classCatbean {Wuyi /** the * Name:matilda - */ Wu - PrivateString name; About $ PublicString GetName () { - returnname; - } - A Public voidsetName (String name) { + This. Name =name; the } - } $ the Public Static classDogbean { the /** the * Name:rufus the * Breed:labrador - * Count:1 in * Twofeet:false the */ the About PrivateString name; the PrivateString breed; the Private intcount; the Private BooleanTwofeet; + - PublicString GetName () { the returnname;Bayi } the the Public voidsetName (String name) { - This. Name =name; - } the the PublicString getbreed () { the returnbreed; the } - the Public voidsetbreed (String breed) { the This. Breed =breed; the }94 the Public intGetCount () { the returncount; the }98 About Public voidSetCount (intcount) { - This. Count =count;101 }102 103 Public BooleanIstwofeet () {104 returnTwofeet; the }106 107 Public voidSettwofeet (BooleanTwofeet) {108 This. Twofeet =Twofeet;109 } the }111 } the}
If you need to look good, configure yourself.
IntelliJ idea parses a string of jsonobject format into an entity via the Gsonformat plugin