How to quickly build Java Bean objects from JSON

Source: Internet
Author: User

When docking with a third party, the JSON time parameter fields that are returned to us are very common, so it's certainly going to take a while for us to create javabean manually, so we can use JSON to automatically generate JavaBean tools, here's a brief introduction to IntelliJ idea Plug-in Gsonformat in the.

1. What is Gsonformat

Converts the JSON data format into a Java Bean object's as plug-in.

2. Shortcut key ctrl+alt+s, or settings-->plugins-and input Gsonformat install Plugins

After installation, restart IntelliJ idea.

Now generate a corresponding bean from the following JSON string.

{    "Success":true,    "msg":"Success",    "ErrorCode":20000,    "Data":{        "Roomid":123,        "isnew":true    }}

First you need a new class file (first to create an empty class, nothing),

Copy the JSON you want to parse.

Then Alt+insert pops up the following screen

Formatting JSON

can set

Generated as follows:

 Public classResponsevo {/*** success:true * msg: Success * errorcode:20000 * data: {"Roomid": 123, "IsNew": true}*/    Private Booleansuccess; PrivateString msg; Private intErrorCode; PrivateDatabean data;  Public Booleanissuccess () {returnsuccess; }     Public voidSetsuccess (Booleansuccess) {         This. Success =success; }     PublicString getmsg () {returnmsg; }     Public voidsetmsg (String msg) { This. msg =msg; }     Public intGetErrorCode () {returnErrorCode; }     Public voidSeterrorcode (intErrorCode) {         This. ErrorCode =ErrorCode; }     PublicDatabean GetData () {returndata; }     Public voidsetData (Databean data) { This. data =data; }     Public Static classDatabean {/*** roomid:123 * isnew:true*/        Private intRoomid; Private Booleanisnew;  Public intGetroomid () {returnRoomid; }         Public voidSetroomid (intRoomid) {             This. Roomid =Roomid; }         Public Booleanisisnew () {returnisnew; }         Public voidSetisnew (Booleanisnew) {             This. isnew =isnew; }    }}

How to quickly build Java Bean objects from JSON

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.