用下面的代码测试,发现并没有调用 @JSONField 注解上 deserializeUsing 指定的 ModelValueDeserializer 类? 版本 1.2.25, 1.2.32 以及最新的 1.2.43 都有问题
public class Main2 {
public static void main(String[] args) {
//ParserConfig.getGlobalInstance().putDeserializer(Model.class, new ModelValueDeserializer());
String json = "{\"value\":123}";
Model model = JSON.parseObject(json, Model.class);
System.out.println(JSON.toJSONString(model));
}
public static class Model {
@JSONField(serializeUsing = ModelValueSerializer.class, deserializeUsing = ModelValueDeserializer.class)
public int value;
}
public static class ModelValueSerializer implements ObjectSerializer {
@Override
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType,
int features) throws IOException {
Integer value = (Integer) object;
String text = value + "元";
serializer.write(text);
}
}
public static class ModelValueDeserializer implements ObjectDeserializer {
@Override
public Integer deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
return parser.getLexer().intValue() * 100;
}
@Override
public int getFastMatchToken() {
return 0;
}
}
}