diff --git a/core/src/main/java/com/alibaba/fastjson2/reader/FieldReaderCollectionMethodReadOnly.java b/core/src/main/java/com/alibaba/fastjson2/reader/FieldReaderCollectionMethodReadOnly.java index 808fccd0e7..755a586974 100644 --- a/core/src/main/java/com/alibaba/fastjson2/reader/FieldReaderCollectionMethodReadOnly.java +++ b/core/src/main/java/com/alibaba/fastjson2/reader/FieldReaderCollectionMethodReadOnly.java @@ -65,7 +65,8 @@ public void accept(T object, Object value) { if ("java.util.Collections$UnmodifiableRandomAccessList".equals(name) || "java.util.Arrays$ArrayList".equals(name) || "java.util.Collections$SingletonList".equals(name) - || name.startsWith("java.util.ImmutableCollections$")) { + || name.startsWith("java.util.ImmutableCollections$") + || name.startsWith("java.util.Collections$Unmodifiable")) { return; } diff --git a/core/src/main/java/com/alibaba/fastjson2/reader/ObjectReaderNoneDefaultConstructor.java b/core/src/main/java/com/alibaba/fastjson2/reader/ObjectReaderNoneDefaultConstructor.java index 59a9989c31..fd27f29c19 100644 --- a/core/src/main/java/com/alibaba/fastjson2/reader/ObjectReaderNoneDefaultConstructor.java +++ b/core/src/main/java/com/alibaba/fastjson2/reader/ObjectReaderNoneDefaultConstructor.java @@ -360,7 +360,7 @@ public T readObject(JSONReader jsonReader, Type fieldType, Object fieldName, lon Object fieldValue = valueMap.get(fieldReader.fieldNameHash); if (fieldValue != null) { - if (paramReader != null) { + if (paramReader != null && (paramReader.fieldName == null || fieldReader.fieldName == null || !paramReader.fieldName.equals(fieldReader.fieldName))) { continue; } fieldReader.accept(object, fieldValue); diff --git a/core/src/test/java/com/alibaba/fastjson2/issues_2900/Issue2901.java b/core/src/test/java/com/alibaba/fastjson2/issues_2900/Issue2901.java new file mode 100644 index 0000000000..26185bbbf7 --- /dev/null +++ b/core/src/test/java/com/alibaba/fastjson2/issues_2900/Issue2901.java @@ -0,0 +1,35 @@ +package com.alibaba.fastjson2.issues_2900; + +import com.alibaba.fastjson2.JSONObject; +import com.alibaba.fastjson2.annotation.JSONField; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Setter; + +import static org.junit.jupiter.api.Assertions.*; + +public class Issue2901 { + @Setter + @Getter + @AllArgsConstructor + public class User { + @JSONField(name = "user_name") + private String userName; + + @Override + public String toString() { + return "User{" + + "userName='" + userName + '\'' + + '}'; + } + } + + void test() { + String str1 = "{\n" + + "\"user_name\":\"zs\"\n" + + "}"; + User user = JSONObject.parseObject(str1, User.class); + assertNotNull(user); + assertEquals(user.getUserName(), "zs"); + } +}