-
Notifications
You must be signed in to change notification settings - Fork 547
Closed
Labels
Milestone
Description
以下为复现代码:
public class TestQuickConfig {
@Test
public void test(){
ObjectWriterProvider provider = new ObjectWriterProvider();
provider.register(Long.class, (out, obj, fieldName, fieldType, features) -> {
String val = obj.toString();
out.writeString(val);
});
JSONWriter.Context context = new JSONWriter.Context(provider,
JSONWriter.Feature.WriteNullStringAsEmpty,
JSONWriter.Feature.WriteNulls);
DemoDo demoDo = new DemoDo();
String json = JSON.toJSONString(demoDo,context);
System.out.println(json); //实际上 s1 输出为 null
assert "{\"n0\":null,\"n1\":\"1\",\"s0\":\"\",\"s1\":\"noear\"}".equals(json);
}
@Getter
@Setter
public static class DemoDo implements Serializable {
String s0;
String s1 = "noear";
Long n0;
Long n1 = 1L; //当有 Long 字段时,才触发这个问题
}
}