mirror of https://github.com/alibaba/fastjson2.git
fix only return null when fist char is n, for issue #3537
This commit is contained in:
parent
436db2bbc5
commit
d9fef743fe
|
@ -123,6 +123,7 @@ public class FieldReaderObject<T>
|
|||
|
||||
Object value;
|
||||
try {
|
||||
char first = jsonReader.current();
|
||||
if (jsonReader.nextIfNullOrEmptyString()) {
|
||||
if (defaultValue != null) {
|
||||
value = defaultValue;
|
||||
|
@ -135,7 +136,7 @@ public class FieldReaderObject<T>
|
|||
} else if (fieldClass == Optional.class) {
|
||||
value = Optional.empty();
|
||||
} else {
|
||||
value = null;
|
||||
value = first == 'n' ? null : "";
|
||||
}
|
||||
} else if (jsonReader.jsonb) {
|
||||
if (fieldClass == Object.class) {
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
package com.alibaba.fastjson2.issues_3500;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class Issue3537 {
|
||||
@Test
|
||||
public void test() {
|
||||
String json = "{\"value\":\"\"}";
|
||||
SimpleTestValue s = JSON.parseObject(json, SimpleTestValue.class);
|
||||
assertEquals("", s.getValue());
|
||||
}
|
||||
|
||||
public static class SimpleTestValue {
|
||||
private Object value;
|
||||
|
||||
// 标准 getter/setter
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
public void setValue(Object value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
// 自定义 getter 会导致问题
|
||||
public List<String> getRelates() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue