dromara / easy-es

A foolproof Elasticsearch ORM framework that is easy to use, requires minimal coding, and is highly expandable...
Apache License 2.0
1.47k stars 233 forks source link

NullPointerException BaseEsMapperImpl json 过滤器导致空指针异常。 #41

Open HPxianliru opened 1 year ago

HPxianliru commented 1 year ago

Caused by: java.lang.NullPointerException at com.alibaba.fastjson.serializer.SerializeWriter.writeFieldValueStringWithDoubleQuoteCheck(SerializeWriter.java:1869) at com.alibaba.fastjson.serializer.SerializeWriter.writeFieldValue(SerializeWriter.java:1854) at com.alibaba.fastjson.serializer.ASMSerializer_2_UserDetail.writeNormal(Unknown Source) at com.alibaba.fastjson.serializer.ASMSerializer_2_UserDetail.write(Unknown Source) at com.alibaba.fastjson.serializer.ASMSerializer_1_ZMessage.writeNormal(Unknown Source) at com.alibaba.fastjson.serializer.ASMSerializer_1_ZMessage.write(Unknown Source) at com.alibaba.fastjson.serializer.JSONSerializer.write(JSONSerializer.java:312) at com.alibaba.fastjson.JSON.toJSONString(JSON.java:793) at com.alibaba.fastjson.JSON.toJSONString(JSON.java:731) at cn.easyes.core.conditions.BaseEsMapperImpl.buildJsonIndexSource(BaseEsMapperImpl.java:1153) at cn.easyes.core.conditions.BaseEsMapperImpl.buildIndexRequest(BaseEsMapperImpl.java:876) 当去除掉项目中的 json 过滤器则可以解析成功。 String json = JSON.toJSONString(zMessage, SerializerFeature.DisableCircularReferenceDetect,SerializerFeature.WriteMapNullValue);

public static void main(String[] args) {
    ZMessage zMessage = new ZMessage();
    zMessage.setAck(true);
    zMessage.setCmd(1);
    UserDetail userDetail = new UserDetail();
    userDetail.setType("ceshi");
    userDetail.setSex("男");

    zMessage.setBody(userDetail);
    zMessage.setUser(userDetail);
    zMessage.setMetadata(new HashMap<>());

    // 字段过滤器
    EntityInfo entityInfo = EntityInfoHelper.getEntityInfo(ZMessage.class);
    List<SerializeFilter> serializeFilters = new ArrayList<>();
    Optional.ofNullable(entityInfo.getClassSimplePropertyPreFilterMap().get(ZMessage.class))
            .ifPresent(serializeFilters::addAll);
    Set<String> excludeColumn = new HashSet<>();
    excludeColumn.add("id");
    // 主类中的字段策略过滤
    SimplePropertyPreFilter simplePropertyPreFilter = FastJsonUtils.getSimplePropertyPreFilter(ZMessage.class, excludeColumn);
    Optional.ofNullable(simplePropertyPreFilter).ifPresent(serializeFilters::add);
    //String json = JSON.toJSONString(zMessage, serializeFilters.toArray(new SerializeFilter[0]), SerializerFeature.DisableCircularReferenceDetect,SerializerFeature.WriteMapNullValue);
    String jsonString = JSON.toJSONString(zMessage, serializeFilters.toArray(new SerializeFilter[0]), SerializerFeature.DisableCircularReferenceDetect,SerializerFeature.WriteMapNullValue);
    //System.out.println(json);
    System.out.println(jsonString);
}

ZMessage { @IndexId(type = IdType.NONE) @ApiModelProperty("nosql主键") private String id; @ApiModelProperty("指令 对应数据字典type值 cmd") private Integer cmd; @ApiModelProperty("消息体") @JSONField(name="body") private Object body; @ApiModelProperty(" true是回执消息,false为非回执消息") private Boolean ack = false; @ApiModelProperty("metadata 元数据自定义 K,V") public Map<String,String> metadata; @ApiModelProperty("用户信息") private UserDetail user; @ApiModelProperty("是否进行回调通知 true 是 false 否") private Boolean ackNotify = false; /**

}

UserDetail { /**

}

版本 esay-es 1.1.0 fastjson 1.2.83

moatkon commented 4 weeks ago

你这个问题解决了吗