This commit is contained in:
Looly 2021-03-13 00:05:25 +08:00
parent 183a820206
commit 76d95d44a8
2 changed files with 5 additions and 6 deletions

View File

@ -285,7 +285,7 @@ public class BeanDesc implements Serializable {
} }
// 包括boolean的任何类型只有一种匹配情况name - getName // 包括boolean的任何类型只有一种匹配情况name - getName
return methodName.equals("get" + fieldName); return methodName.equals("get" + handledFieldName);
} }
/** /**
@ -322,10 +322,10 @@ public class BeanDesc implements Serializable {
} }
// 针对Boolean类型特殊检查 // 针对Boolean类型特殊检查
if (isBooleanField && handledFieldName.startsWith("is")) { if (isBooleanField && fieldName.startsWith("is")) {
// 字段是is开头 // 字段是is开头
if (methodName.equals("set" + StrUtil.removePrefix(fieldName, "is"))// isName - setName if (methodName.equals("set" + StrUtil.removePrefix(fieldName, "is"))// isName - setName
|| methodName.equals("set" + fieldName)// isName - setIsName || methodName.equals("set" + handledFieldName)// isName - setIsName
) { ) {
return true; return true;
} }

View File

@ -216,7 +216,6 @@ public class JSONObjectTest {
@Test @Test
public void toBeanWithNullTest() { public void toBeanWithNullTest() {
String jsonStr = "{'data':{'userName':'ak','password': null}}"; String jsonStr = "{'data':{'userName':'ak','password': null}}";
Console.log(JSONUtil.parseObj(jsonStr));
UserWithMap user = JSONUtil.toBean(JSONUtil.parseObj(jsonStr), UserWithMap.class); UserWithMap user = JSONUtil.toBean(JSONUtil.parseObj(jsonStr), UserWithMap.class);
Assert.assertTrue(user.getData().containsKey("password")); Assert.assertTrue(user.getData().containsKey("password"));
} }
@ -518,7 +517,7 @@ public class JSONObjectTest {
final Map.Entry<String, String> next = entries.iterator().next(); final Map.Entry<String, String> next = entries.iterator().next();
final JSONObject jsonObject = JSONUtil.parseObj(next); final JSONObject jsonObject = JSONUtil.parseObj(next);
Console.log(jsonObject); Assert.assertEquals("{\"test\":\"testValue\"}", jsonObject.toString());
} }
@Test(expected = JSONException.class) @Test(expected = JSONException.class)
@ -533,7 +532,7 @@ public class JSONObjectTest {
map.put("c", 2.0F); map.put("c", 2.0F);
final String s = JSONUtil.toJsonStr(map); final String s = JSONUtil.toJsonStr(map);
Console.log(s); Assert.assertEquals("{\"c\":2}", s);
} }
@Test @Test