Skip to content

Commit

Permalink
Issue2901问题fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
mek1986 authored and wenshao committed Sep 2, 2024
1 parent 6ebb67b commit c9c2bc1
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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");
}
}

0 comments on commit c9c2bc1

Please sign in to comment.