Skip to content

Commit

Permalink
Issue2901问题fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
mek1986 committed Aug 31, 2024
1 parent 5fca4b8 commit 5b87e79
Show file tree
Hide file tree
Showing 3 changed files with 37 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$UnmodifiableCollection")) {
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,34 @@
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 org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class Issue2901 {
@Setter
@Getter
@AllArgsConstructor
public class User {
@JSONField(name = "user_name")
private String userName;

@Override
public String toString() {
return "User{" +
"userName='" + userName + '\'' +
'}';
}
}
@Test
void test() {
String str1 = "{\n" +
"\"user_name\":\"zs\"\n" +
"}";
User user = JSONObject.parseObject(str1, User.class);
Assertions.assertEquals(user.getUserName(), "zs");
}
}

0 comments on commit 5b87e79

Please sign in to comment.