ENUM
Introduction
Verify whether the request parameter of the enumeration type is in the enumeration value list.
Example
Data Dictionary
hrm.employees Human Resources System - Employee Table
| Column name | Data type | Not empty | Increment | Key | Description | |------------|---------------|----|----|----|----- ---| | emp_no | int(11) | yes | - | primary key | employee unique number | | birth_date | date | yes | - | - | birthday | | first_name | varchar(14) | yes | - | - | last name | | last_name | varchar(16) | is | - | - | first name | | gender | enum('M','F') | yes | - | - | gender | | hire_date | date | yes | - | - | hire_date |
Parameter mapping and verification
Parameter object's gender field maps hrm.departments table gender column
Before inserting data, verify that the gender data type meets the following rules
- Must be 'M' or 'F', where M means male and F means female
ask
POST http://127.0.0.1:21000
Content-Type: application/json;charset=utf-8
{
"jsonrpc": "2.0",
"method": "hrm.employees.add",
"params": {
"empNo": 20000,
"birthDate": "1964-06-02",
"firstName": "Bezalel",
"lastName": "Simmel",
"gender": "E",
"hireDate": "1985-11-21"
},
"id": "client-unique-request-id"
}
Response
The request was intercepted and an error was reported, indicating that the written value was not in the enumeration list and the operation was refused.
HTTP/1.1 400 Bad Request
Content-Type: application/json; charset=utf-8
{
"jsonrpc": "2.0",
"error": {
"code": -32602,
"message": "validating data type: gender: E does not validate as in(M|F)",
"data": {
"errorCode": "EU.Validator.DataTypeError",
"errorDetails": [
{
"field": "gender",
"fieldValue": "E",
"location": "hrm.employees",
"message": "gender: E does not validate as in(M|F)",
"validator": "in"
}
],
"errorMessage": "gender: E does not validate as in(M|F)"
}
},
"id": "client-unique-request-id"
}
Remarks: The above example was tested in Luwak 1.12.9.