-
public
class
Outer {
private
int
a;
private
String b;
public
int
getA() {
return
a;
}
public
void
setA(
int
a) {
this
.a = a;
}
public
String getB() {
return
b;
}
public
void
setB(String b) {
this
.b = b;
}
}
public
static
void
main(String[] args) {
String json = JSON.toJSONString(
new
Outer(), SerializerFeature.WriteMapNullValue);
System.out.println(json);
}
输出结果:
{"a":0,"b":null}
然后反转:
1
2
String json =
"{'a':0,'b':null}"
;
System.out.println(JSON.parseObject(json, Outer.
class
, Feature.IgnoreNotMatch));
fastjson parse 字符串转成对象时解析怎样保留null字段
最新推荐文章于 2025-04-15 14:42:24 发布