Get the App
SLTechnology News&Howtos  ›  Development  › 

How to quickly convert JSON to objects in Idea plug-ins

Shulou Source: shulou.com Published: 2022-06-03 11:57:50 10月04日 Update

How to quickly JSON objects in the Idea plug-in, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can get something.

In development, there is often a scenario in which an JSON example is given and then defined as an object class to co-debug and test with the front end. If the Json is very long, a lot of time will be wasted on writing object classes.

Next, we recommend a plug-in for Idea: GsonFormatPlus (secondary development based on GsonFormat).

Installation

Search for GsonFormatPlus installation directly in Plugins-> Marketplace of Idea:

GsonFormatPlus

After installation, you need to restart Idea to take effect.

If the installation fails from Marketplace, you can download the plug-in's zip package and install it from disk.

Use

Here is a Json to test:

{"name": "Wang Wu", "gender": "man", "age": 15, "height": "140cm", "addr": {"province": "fujian", "city": "quanzhou", "code": "300000"} "hobby": [{"name": "billiards", "code": "1"}, {"name": "computerGame", "code": "2"}]}

In Idea, click Code-> Generate-> GsonFormatPlus:

You can also directly use the shortcut key Alt+S to generate it. The interface is as follows:

Type JSON on the left, and then you can set it in Setting according to your needs:

For example, whether to use Lombok, whether to use comments, field modifier selection, etc., you can try it yourself.

Click OK to generate, and you can also fill in the comments of the field when you generate it. The default comment information is the field name.

Click OK to generate the corresponding class:

Is it very simple? If you need it, you can try to download the plug-in yourself, which can improve the coding efficiency.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Tags: Plug-ins generation objects fields comments attempts help development testing clarity next examples information content front end scenarios for this frequent meetings shortcuts efficiency Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Microsoft Shulou Tech Info Shulou Technology Huawei