fix BeanUtils#getEnumValueField, for issue #2682 #2821
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What this PR does / why we need it?
修复了 [#2682] 。
我碰见了和 [#2682] 一样的问题
如果继承了
com.baomidou.mybatisplus.annotation.IEnum<T extends Serializable>
类,并且需要使用IEnum#getValue
方法或者注解上面添加@JSONField(value = true)
注解。json反序列化:执行到
BeanUtils#getEnumValueField
方法,里面获取所有的Method
进行循环,这时候继承了IEnum
接口会找到俩名称个一样的Method
方法。只不过getReturnType
返回类不同,并在if (methodName.startsWith("get")) {
分支中没有对同名方法做处理。最后到了new ObjectReaderImplEnum
方法的时候 ,如下代码首先获取了
Serializable
(继承了 IEnum 接口) 。然后在如下代码中就会使用 intValues 。在下面解析的时候就会出现bug。
如果使用里面的
BizType
枚举是无法复原该bug,在调用#.getMethods()
获取所有方法的时候,String getValue()
在Serializable getValue
之前。我创建了
com.alibaba.fastjson2.issues_2600.Issue2682#RobotActEnum
枚举,该枚举可以保证Serializable getValue
在String getValue()
之前,然后触发这个bug。请问一下这个class
反射获取所有方法的时候顺序是怎样造成的。我是在
BeanUtils#getEnumValueField
中的if (methodName.startsWith("get")) {
里面 如果发现俩个方法名称完全一样,就认为是重写
方法,然后使用isAssignableFrom
确认子类的方法是哪个 (枚举中使用子类)Summary of your change
修复 BeanUtils#getEnumValueField
Please indicate you've done the following: