Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Bool type serialization #673 and enhanced #587 #686

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,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
35 changes: 35 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,35 @@
package com.alibaba.fastjson2.issues;

import com.alibaba.fastjson2.JSON;
import org.junit.jupiter.api.Test;

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

/**
* @author kraity
*/
public class Issue673 {
@Test
public void test() {
String json = JSON.toJSONString(new Bean());
assertEquals("{\"me\":true,\"me2\":true,\"ok\":true,\"ok2\":true}", json);
}

static class Bean {
public boolean isMe() {
return true;
}

public boolean getMe2() {
return true;
}

public Boolean isOk() {
return Boolean.TRUE;
}

public Boolean getOk2() {
return Boolean.TRUE;
}
}
}
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