Skip to content

Commit

Permalink
serialize support Boolean isXX getter, fix issue #673
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Aug 26, 2022
1 parent 9834a39 commit e7f63f5
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ boolean record = isRecord(objectClass);
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);
Expand Down
27 changes: 27 additions & 0 deletions core/src/test/java/com/alibaba/fastjson2/issues/Issue673.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit e7f63f5

Please # to comment.