Home > Back-end >  Hutool Json parsing alias
Hutool Json parsing alias

Time:12-24

Hutool Json parsing Json to the entity class, how to use an alias.

1. The Json string

 
{
"Errcode" : 0,
"Errmsg" : "ok,"
"Department" : [
{
"Id" : 2,
"Name" : "guangzhou research and development center,"
"Name_en" : "RDGZ,"
"Parentid" : 1,
"Order" : 10
},
{
"Id" : 3,
"Name" : "email products division,"
"Name_en" : "mail",
"Parentid" : 2,
"Order" : 40
}
]
}


2. The entity class
 
/*
* @ Author: Administrator
* @ DateTime: 2020/12/7 16:05
* @ Description: department
*/
Public class WeChat_Department implements Serializable {

/* department id */
Private Long departmentId;

/* department name */
private String name;

/* English name
This field since December 30, 2019, the newly created third-party applications no longer return, on June 30, 2020, history of all third party applications no longer return to the field */
Private String nameEn;

/* parent department id
The root department for 1 */
Private Long parentId.

/* the order of the values in the parent department
The order value of sort, value range is [0, 2 ^ 32) */
Private Long order;
}


The inside of the json "id" is corresponding to the inside of the entity class departmentId, so it can't take it out

CodePudding user response:

@ Data
Public static class BeanWithAlias {
@ Alias (" name ")
Private String value1.
@ Alias (" age ")
Private Integer value2.
}
  • Related