serialize support Boolean isXX getter, fix issue #673

This commit is contained in:
shaojin.wensj 2022-08-27 00:52:30 +08:00
parent 9834a39435
commit e7f63f59e5
4 changed files with 30 additions and 3 deletions

View File

@ -690,7 +690,7 @@ public abstract class BeanUtils {
if (firstChar >= 'a' && firstChar <= 'z' && methodNameLength == 4) {
nameMatch = false;
}
} else if (returnClass == boolean.class) {
} else if (returnClass == boolean.class || returnClass == Boolean.class) {
nameMatch = methodNameLength > 2 && methodName.startsWith("is");
if (nameMatch) {
char firstChar = methodName.charAt(2);

View File

@ -0,0 +1,27 @@
package com.alibaba.fastjson2.issues;
import com.alibaba.fastjson2.JSON;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class Issue673 {
@Test
public void test() throws Exception {
Bean bean = new Bean();
bean.value = true;
assertEquals("{\"value\":true}", JSON.toJSONString(bean));
}
public static class Bean {
private Boolean value;
public Boolean isValue() {
return value;
}
public void setValue(Boolean value) {
this.value = value;
}
}
}

View File

@ -13,7 +13,7 @@ public class Issue1496 {
@Test
public void test_for_issue() throws Exception {
String json = JSON.toJSONString(SetupStatus.FINAL_TRAIL);
assertEquals("{\"canRefuse\":true,\"code\":3,\"name\":\"FINAL_TRAIL\",\"nameCn\":\"公益委员会/理事会/理事长审核\"}", json);
assertEquals("{\"canRefuse\":true,\"code\":3,\"first\":false,\"last\":false,\"name\":\"FINAL_TRAIL\",\"nameCn\":\"公益委员会/理事会/理事长审核\"}", json);
}
public interface ISetupStatusInfo {

View File

@ -13,7 +13,7 @@ public class Issue1496 {
@Test
public void test_for_issue() throws Exception {
String json = JSON.toJSONString(SetupStatus.FINAL_TRAIL);
assertEquals("{\"canRefuse\":true,\"code\":3,\"name\":\"FINAL_TRAIL\",\"nameCn\":\"公益委员会/理事会/理事长审核\"}", json);
assertEquals("{\"canRefuse\":true,\"code\":3,\"first\":false,\"last\":false,\"name\":\"FINAL_TRAIL\",\"nameCn\":\"公益委员会/理事会/理事长审核\"}", json);
}
public interface ISetupStatusInfo {