1. 程式人生 > >Idea中GsonFormat外掛安裝

Idea中GsonFormat外掛安裝

外掛地址:https://plugins.jetbrains.com/idea/plugin/7654-gsonformat

這個教程主要是學習IntelliJ IDEA 如何通過GsonFormat外掛將JSONObject格式的String 解析成實體。

一般來說

IDEA的外掛安裝非常簡單,對於很多外掛來說,只要你知道外掛的名字就可以在IDEA裡面直接安裝。
File->Settings->Plugins—>查詢所需外掛—>Install
或者
File->Settings->Plugins—>Install plug from disk —>選擇下載好的外掛安裝

一般外掛安裝之後重啟IDEA即可生效。

下面詳細安裝圖文:

先到setting裡面,然後通過搜尋Plugins

然後外掛欄搜尋GsonFormat。

安裝即可。

安裝完,需要重啟一下idea。

 

通過json

 

1

2

3

4

5

6

7

8

9

{

"animals":{

"dog":[

{"name":"Rufus","breed":"labrador","count":1,"twoFeet":false},

{"name":"Marty","breed":"whippet","count":1,"twoFeet":false}

],

"cat":{"name":"Matilda"}

}

}

 

自定義個javaBean(無任何內容,就一個空的類)

複製你要解析的json

然後alt+insert彈出如下介面 或者使用快捷鍵 alt+s

通過快捷鍵調出該外掛

格式化json

可以設定

ok即可生成實體類

配置生成名

生成如下:

package com.yuanding.entity;
 
import java.util.List;
 
/**
* Created by diyvc on 2017/3/13.
*/
public class TestClass {
 
 
    /**
     * animals : {"dog":[{"name":"Rufus","breed":"labrador","count":1,"twoFeet":false},{"name":"Marty","breed":"whippet","count":1,"twoFeet":false}],"cat":{"name":"Matilda"}}
     */
 
    private AnimalsBean animals;
 
    public AnimalsBean getAnimals() {
        return animals;
    }
 
    public void setAnimals(AnimalsBean animals) {
        this.animals = animals;
    }
 
    public static class AnimalsBean {
        /**
         * dog : [{"name":"Rufus","breed":"labrador","count":1,"twoFeet":false},{"name":"Marty","breed":"whippet","count":1,"twoFeet":false}]
         * cat : {"name":"Matilda"}
         */
 
        private CatBean cat;
        private List<DogBean> dog;
 
        public CatBean getCat() {
            return cat;
        }
 
        public void setCat(CatBean cat) {
            this.cat = cat;
        }
 
        public List<DogBean> getDog() {
            return dog;
        }
 
        public void setDog(List<DogBean> dog) {
            this.dog = dog;
        }
 
        public static class CatBean {
            /**
             * name : Matilda
             */
 
            private String name;
 
            public String getName() {
                return name;
            }
 
            public void setName(String name) {
                this.name = name;
            }
        }
 
        public static class DogBean {
            /**
             * name : Rufus
             * breed : labrador
             * count : 1
             * twoFeet : false
             */
 
            private String name;
            private String breed;
            private int count;
            private boolean twoFeet;
 
            public String getName() {
                return name;
            }
 
            public void setName(String name) {
                this.name = name;
            }
 
            public String getBreed() {
                return breed;
            }
 
            public void setBreed(String breed) {
                this.breed = breed;
            }
 
            public int getCount() {
                return count;
            }
 
            public void setCount(int count) {
                this.count = count;
            }
 
            public boolean isTwoFeet() {
                return twoFeet;
            }
 
            public void setTwoFeet(boolean twoFeet) {
                this.twoFeet = twoFeet;
            }
        }
    }
}

 

需要好看的話,自己配置一下。