Assuming the following enum class exists
public enum UserType {
//Admin
ADMIN(1, "Admin"),
//Member
MEMBER(2, "Member"),
//Guest
GUEST(3, "Guest");
private int type;
private String desc;
public int getType() {
return type;
}
public String getDesc() {
return desc;
}
UserType(int type, String desc) {
this.type = type;
this.desc = desc;
}
}
For the following field:
/**
* User type
*/
private UserType type;
/**
* User type
* @see UserType
*/
private String type;
name | type | required | default | desc | other |
---|---|---|---|---|---|
type | string | NO | USER type | ENUM: ADMIN,MEMBER,GUEST ENUMdesc: ADMIN :Admin MEMBER :Member GUEST :Guest mock: @pick(["ADMIN","MEMBER","GUEST"]) |
int
and use the type
field of the enum as the available values, add the following configuration:json.rule.enum.convert[com.itangcent.common.constant.UserType]=~#type
/**
* USER type
* @see UserType#type
*/
private int type;
name | type | required | default | desc | other |
---|---|---|---|---|---|
type | integer | NO | USER type | ENUM: 1,2,3 ENUMdesc: 1 :Admin 2 :Member 3 :Guest mock: @pick([1,2,3]) |
package com.itangcent.common.constant;
public interface TypeAble {
int getType();
}
UserType
enum to implement TypeAble
:public enum UserType implements TypeAble {
...
}
TypeAble
to int
and use the type
field of the enum as the available values:json.rule.enum.convert[groovy:it.extend("com.itangcent.common.constant.TypeAble")]=~#type