Map类型字段fastjson保存序列化问题
tomZF opened this issue · comments
Caused by: ElasticsearchException[Elasticsearch exception [type=json_parse_exception, reason=Unexpected character ('n' (code 110)): was expecting double-quote to start field name
.....
`@Data
@IndexName("demo")
public class EasyEsDemo {
@IndexId
private String id;
private String name;
private int age;
// 这个Map字段因为NameFilter过滤器,导致fastjson序列化后为{null:"value"}这种形式,insert报错
private Map<String, Object> data;
}
`
EntityInfoHelper中创建的NameFilter是一个匿名类,看上去主要功能就是过滤排除字段,但是针对Map类型字段就出现了问题,导致序列化时候Map的key字段变成了个null. 是不是还有别的方式处理这种情况?
还是说EntityInfoHelper中创建的NameFilter可以留个口允许自定义实现?
目前的处理方式是自定义了一个MapSerializer,使用@JSONField(serializeUsing = MyMapSerializer.class)注解data字段
`
public static class MyMapSerializer extends MapSerializer {
@OverRide
protected String processKey(JSONSerializer jsonBeanDeser, Object object, String key, Object propertyValue) {
// 删除了 jsonBeanDeser.nameFilters 的处理逻辑
if (this.nameFilters != null) {
for (NameFilter nameFilter : this.nameFilters) {
key = nameFilter.process(object, key, propertyValue);
}
}
return key;
}
}
`
@IndexField(nestedClass = yourClassName.class) 有这样一个嵌套内部类的注解也许是可以试试。