Skip to content

Commit

Permalink
fix change to isInt for ObjectReaderImplEnum, for issue #2682
Browse files Browse the repository at this point in the history
  • Loading branch information
yanxutao89 committed Jun 10, 2024
1 parent 20a2547 commit 801e1ae
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public Object readObject(JSONReader jsonReader, Type fieldType, Object fieldName
// ignored
}
}
} else if (intValues != null && jsonReader.isString()) {
} else if (intValues != null && jsonReader.isInt()) {
int intValue = jsonReader.readInt32Value();
for (int i = 0; i < intValues.length; i++) {
if (intValues[i] == intValue) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.alibaba.fastjson2.issues_2600;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.EnumValue;
import com.baomidou.mybatisplus.annotation.IEnum;
import lombok.Data;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class Issue2682 {
@Test
public void test() {
String str = "{\"bizType\":\"common\"}";
VM vm = JSON.parseObject(str, VM.class);
assertEquals(BizType.COMMON, vm.getBizType());
}

@Data
public static class VM {
private BizType bizType;
}

public enum BizType
implements IEnum<String> {
COMMON("common", "通用");

BizType(String value, String name) {
this.value = value;
this.name = name;
}

@EnumValue
private final String value;
private final String name;

@JSONField(value = true)
public String getValue() {
return value;
}

public String getName() {
return name;
}

public static void test123() {
}
}
}

0 comments on commit 801e1ae

Please sign in to comment.