The background returns to the front-end is.... the beginning field is blocked

The background returns to the front end is.... the beginning field is blocked (Java)
background :

As usual, the front-end joint debugging interface received feedback from the front-end colleagues that a certain field returned by two identical interfaces is different.

实体类 :
public class Test{
    
    
	private Boolean isEnable;
}

==============================
前端接收到的数据 : 
{
    
    
	"enable":true
}

Problem: The field name received by the front end is inconsistent with the definition!!! It is very strange. After checking the code without errors, a sentence in <Alibaba Development Manual> comes to mind, which explicitly prohibits the Boolean type that has been defined at the beginning of is The variable naming method:

[Mandatory] Do not add is to Boolean variables in the POJO class, otherwise part of the frame parsing will cause serialization errors.
Counter-example: It is defined as a property of the basic data type Boolean isDeleted;, and its method is also isDeleted(). When the RPC framework reverses the analysis, it "thinks" that the corresponding property name is deleted, resulting in the property not being obtained, and then throwing an exception .

Therefore, standardizing variable names is the best recommendation. Of course, there are several ways to solve this problem more conveniently.

1. Add serialization annotations.

@JsonProperty(value = “isEnable”)
pirvate Boolean isEnable;

2. Modify the get/set method corresponding to the entity field to start with is.


OVER See You Later !

Guess you like

Origin blog.csdn.net/AKALXH/article/details/126118801