You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.
import com.alibaba.fastjson.serializer.AfterFilter;
import com.alibaba.fastjson.serializer.JSONSerializer;
import com.alibaba.fastjson.serializer.SerializeConfig;
import com.alibaba.fastjson.serializer.SerializeWriter;
import com.alibaba.fastjson.serializer.SerializerFeature;
public class Main {
public static void main(String[] args) {
Json json = new Json();
json.setOp(new Operator());
try(SerializeWriter out = new SerializeWriter()) {
JSONSerializer s = new JSONSerializer(out, new SerializeConfig());
s.config(SerializerFeature.DisableCircularReferenceDetect, true);
s.getAfterFilters().add(new JsonFilter());
s.write(json);
System.out.println(out.toString());
}
}
static class Json {
private Operator op;
public Operator getOp() {
return op;
}
public void setOp(Operator op) {
this.op = op;
}
}
static class Operator {
}
static class JsonFilter extends AfterFilter {
@Override
public void writeAfter(Object object) {
if(object instanceof Operator) {
writeKeyValue("operator", "operator");
}
}
}
}
exception stack
Exception in thread "main" com.alibaba.fastjson.JSONException: write javaBean error, fastjson version 1.2.73, class cn.nextop.thorin.admin.json.Main$Json, write javaBean error, fastjson version 1.2.73, class cn.nextop.thorin.admin.json.Main$Operator, fieldName : op
at com.alibaba.fastjson.serializer.JavaBeanSerializer.write(JavaBeanSerializer.java:539)
at com.alibaba.fastjson.serializer.JavaBeanSerializer.write(JavaBeanSerializer.java:149)
at com.alibaba.fastjson.serializer.JSONSerializer.write(JSONSerializer.java:312)
at cn.nextop.thorin.admin.json.Main.main(Main.java:41)
Caused by: com.alibaba.fastjson.JSONException: write javaBean error, fastjson version 1.2.73, class cn.nextop.thorin.admin.json.Main$Operator, fieldName : op
at com.alibaba.fastjson.serializer.JavaBeanSerializer.write(JavaBeanSerializer.java:539)
at com.alibaba.fastjson.serializer.JavaBeanSerializer.write(JavaBeanSerializer.java:149)
at com.alibaba.fastjson.serializer.FieldSerializer.writeValue(FieldSerializer.java:320)
at com.alibaba.fastjson.serializer.JavaBeanSerializer.write(JavaBeanSerializer.java:470)
... 3 more
Caused by: java.lang.NullPointerException
at com.alibaba.fastjson.serializer.AfterFilter.writeKeyValue(AfterFilter.java:26)
at cn.nextop.thorin.admin.json.Main$JsonFilter.writeAfter(Main.java:70)
at com.alibaba.fastjson.serializer.AfterFilter.writeAfter(AfterFilter.java:17)
at com.alibaba.fastjson.serializer.JavaBeanSerializer.writeAfter(JavaBeanSerializer.java:834)
at com.alibaba.fastjson.serializer.JavaBeanSerializer.write(JavaBeanSerializer.java:502)
... 6 more
it works in 1.2.72
reproduce code
exception stack
fastjson version: 1.2.73
jdk version: openjdk-11.0.2
The text was updated successfully, but these errors were encountered: