GsonFormat of Android studio plug-in (automatically generate javabean)

Source: Internet
Author: User

GsonFormat of Android studio plug-in (automatically generate javabean)
Overview

I believe that you have written a lot of javabean during the development process. In many cases, a list of data is a single javabean. If you think about it yourself, it is time-consuming, laborious, and easy to make mistakes.

Today, we recommend a plug-in GsonFormat that allows us to directly convert the json returned by the server to an entity class. Android studio and idea both have one. I have not tried eclipse. You can check whether there is any.

Step 1 download the plug-in

Before downloading the plug-in, I have a blog with detailed steps: sexy editor for Android Studio plug-in (set the AS background). You only need to replace the plug-in name described in that blog with GsonFormat.

Follow these steps to download the plug-in. Remember to download and install it and restart it.

Step 2 automatically generate bean

The following describes how to use this plug-in to automatically generate a javabean

 

First, we need to create an empty java class, and then right-click the blank and select Generate... if you have installed the plug-in successfully, the following box will pop up.

 

Select GsonFormat. The following box is displayed.

 

Paste the json returned by the server to this directory and click OK.

 

After pasting, click OK. The selection field interface shown in is displayed.

 

 

This interface allows you to choose which fields to retain. You can remove the preceding check box if you do not need some fields. Click OK.

 

Paste the json string and automatically generated bean code.

Json string

 

{"retval":"ok","reterr":"","retinfo":{"count":2,"groups":[{"groupid":1,"title":"\u65b0\u670b\u53cb","icon":"http:\/\/aliimg.yizhibo.tv\/online\/message\/2f\/74\/hi.png","type":"1","readcnt":67,"unread":2,"total":19,"update_time":"2016-04-05 09:11:09","lastest_content":{"type":2,"data":{"name":"16837286","nickname":"\u963f\u83b2","gender":"female","signature":"","vip":"0","logourl":"http:\/\/aliimg.yizhibo.tv\/online\/user\/2c\/17\/60ec3f44e8a0de9db1d87f1a59875ce1.jpg@100h_100w_90Q_0e_1c"}}},{"groupid":0,"title":"\u6613\u76f4\u64ad\u5c0f\u79d8\u4e66","icon":"http:\/\/aliimg.yizhibo.tv\/online\/message\/07\/fd\/Secretary.png","type":0,"readcnt":86,"unread":0,"total":86,"update_time":"2016-04-01 00:09:28","lastest_content":{"type":0,"data":{"text":"\u611a\u4eba\u8282\u6765\u4e34\u4e4b\u9645\uff0c\u5fc3\u4e2d\u7684\u5c0f\u6076\u9b54\u6b63\u5728\u9a9a\u52a8\u3002\u6613\u76f4\u64ad\u611a\u4eba\u8282\u65e0\u654c\u5927\u738b\u4e89\u9738\u96c6\u7ed3\u53f7\u4e5f\u501f\u52bf\u90aa\u6076\u5439\u54cd\uff01\u770b\u5404\u5927\u5bb6\u5982\u4f55\u5927\u65bd\u8ff7\u9b42\u9635\uff0c\u6597\u5fd7\u6597\u52c7\uff0c\u620e\u9a6c\u800c\u5f52\u3002\u201c\u611a\u4eba\u5927\u738b\u201d\u3001\u201c\u8303\u4e8c\u5927\u738b\u201d\u7a76\u7adf\u82b1\u843d\u8c01\u5bb6\u5462\uff1f\u54b1\u4eec\u62ed\u76ee\u4ee5\u5f85\uff01"}}}]}}

Generated bean

 

 

 

Import java. util. list; public class MessageGroupEntity {/*** retval: OK * reterr: * retinfo: {"count": 2, "groups": [{"groupid": 1, "title": "New Friend", * "icon": "http://aliimg.yizhibo. TV /online/message/2f/74/hi.png", "type": "1", "readcnt": 67, * "unread": 2, "total": 19, "update_time": "09:11:09", "lastest_content": {"type": 2, * "data": {"name": "16837286 ", "nickname": "Alian", "gender": "female", "signature ":"", "Vip": "0", * "logourl": "http://aliimg.yizhibo. TV /online/user/2c/17/60ec3f44e8a0de9db1d87f1a59875ce1.jpg@100h_100w_90Q_0e_1c" }}*, {"groupid": 0, "title": "Easy live small secretary ", "icon": "http://aliimg.yizhibo. TV /online/message/07/fd/Secretary.png", "type": 0, "readcnt": 86, * "unread": 0, "total": 86, "update_time ": "00:09:28", * "lastest_content": {"type": 0, "data": {"text": "the little devil in your mind is in turmoil when the Fool's Day is approaching. Yizhibo, the invincible king of yuexiao, competed against the storm! * Let's take a look at how everyone gets involved, fighting for courage, and returning from the horse. \ U201c: Who exactly did the u C, u201c, FAN 2, and u201d? Wait and see! "}}}]} */Private String retval; private String reterr;/*** count: 2 * groups: [{" groupid ": 1," title ": "New Friend", * "icon": "http://aliimg.yizhibo. TV /online/message/2f/74/hi.png", "type": "1", "readcnt": 67, * "unread": 2, "total ": 19, "update_time": "09:11:09", * "lastest_content": {"type": 2, "data": {"name": "16837286", "nickname ": "Alian", "gender": "female", * "signature": "", "vip": "0", "logourl": "http: // ali Img. yizhibo. TV/online/user/2c/17/60 videos @ 100h_100w_90Q_0e_1c "}}, * {" groupid ": 0," title ":" Easy live small secretary "," icon ": "http://aliimg.yizhibo. TV /online/message/07/fd/Secretary.png", * "type": 0, "readcnt": 86, "unread": 0, "total": 86, "update_time": "00:09:28 ", "lastest_content": * {"type": 0, "data": {"text": "the little devil in your mind is in turmoil when the Fool's Day is approaching. Yizhibo, the invincible king of yuexiao, competed against the storm! Let's take a look at how everyone gets involved. * \ U201c: Who exactly did the u D? Wait and see! "}}] */Private RetinfoEntity retinfo; public void setRetval (String retval) {this. retval = retval;} public void setReterr (String reterr) {this. reterr = reterr;} public void setRetinfo (RetinfoEntity retinfo) {this. chain info = chain Info;} public String getRetval () {return retval;} public String getReterr () {return reterr;} public chain Info () {return chain Info ;} public static class RetinfoEntity {private int count;/*** groupid: 1 * title: new friend * icon: http://aliimg.yizhibo. TV /online/message/2f/74/hi.png * type: 1 * readcnt: 67 * unread: 2 * total: 19 * update_time: 09:11:09 * lastest_content: {"type": 2, "data": {"name": "16837286", "nickname": "Alian ", "gender": "female", "signature": "", "vip": "0", "logourl": "http://aliimg.yizhibo. TV /online/user/2c/17/60ec3f44e8a0de9db1d87f1a59875ce1.jpg@100h_100w_90Q_0e_1c"} */private List
 
  
Groups; public void setCount (int count) {this. count = count;} public void setGroups (List
  
   
Groups) {this. groups = groups;} public int getCount () {return count;} public List
   
    
GetGroups () {return groups;} public static class GroupsEntity {private int groupid; private String title; private String icon; private String type; private int readcnt; private int unread; private int total; private String update_time;/*** type: 2 * data: {"name": "16837286", "nickname": "Alian", "gender ": "female", "signature": "", "vip": "0", "logourl": "http://aliimg.yizhibo. TV /online/user/2c/17/60ec3f44e8a0de9db1d87f1a59875ce1.jpg@100h_100w_90Q_0e_1c"} */private LastestContentEntity lastest_content; public void setGroupid (int groupid) {this. groupid = groupid;} public void setTitle (String title) {this. title = title;} public void setIcon (String icon) {this. icon = icon;} public void setType (String type) {this. type = type;} public void setReadcnt (int readcnt) {this. readcnt = readcnt;} public void setUnread (int unread) {this. unread = unread;} public void setTotal (int total) {this. total = total;} public void setUpdate_time (String update_time) {this. update_time = update_time;} public void setLastest_content (LastestContentEntity lastest_content) {this. lastest_content = lastest_content;} public int getGroupid () {return groupid;} public String getTitle () {return title;} public String getIcon () {return icon;} public String getType () {return type;} public int getReadcnt () {return readcnt;} public int getUnread () {return unread;} public int getTotal () {return total;} public String getUpdate_time () {return update_time;} public LastestContentEntity getLastest_content () {return lastest_content;} public static class LastestContentEntity {private int type;/*** name: 16837286 * nickname: Alian * gender: female * signature: * vip: 0 * logourl: http://aliimg.yizhibo. TV /online/user/2c/17/60ec3f44e8a0de9db1d87f1a59875ce1.jpg@100h_100w_90Q_0e_1c */private DataEntity data; public void setType (int type) {this. type = type;} public void setData (DataEntity data) {this. data = data;} public int getType () {return type;} public DataEntity getData () {return data;} public static class DataEntity {private String name; private String nickname; private String gender; private String signature; private String vip; private String logourl; public void setName (String name) {this. name = name;} public void setNickname (String nickname) {this. nickname = nickname;} public void setGender (String gender) {this. gender = gender;} public void setSignature (String signature) {this. signature = signature;} public void setVip (String vip) {this. vip = vip;} public void setLogourl (String logourl) {this. logourl = logourl;} public String getName () {return name;} public String getNickname () {return nickname;} public String getGender () {return gender;} public String getSignature () {return signature;} public String getVip () {return vip;} public String getLogourl () {return logourl ;}}}}}}
   
  
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.