Skip to content

Commit

Permalink
fix boolean field annotation not work, for issue #2795
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Jul 13, 2024
1 parent 0c940d4 commit 970ed31
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions core/src/main/java/com/alibaba/fastjson2/util/BeanUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -1226,6 +1226,8 @@ public static Field getField(Class objectClass, Method method) {
} else if (fieldName.regionMatches(0, methodName, prefix, fieldNameLength)) {
fields[1] = field;
}
} else if (boolean.class == field.getType() && methodName.equals(fieldName)) {
fields[0] = field;
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.alibaba.fastjson2.issues_2700;

import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson2.JSONObject;
import lombok.Builder;
import lombok.Data;
import org.junit.jupiter.api.Test;

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

public class Issue2795 {
@Builder
@Data
public static class Student {
@JSONField(name = "is_judge")
private boolean isJudge;
}

@Test
public void testFastJson() {
Student student = Student.builder().isJudge(true).build();
System.out.println(com.alibaba.fastjson.JSON.toJSONString(student));
assertEquals("{\"is_judge\":true}", JSONObject.toJSONString(student));
}
}

0 comments on commit 970ed31

Please sign in to comment.