我有一个自定义反序列化类,我用它来确保null双精度被反序列化为null而不是0.0
public class DoubleDeserializer extends JsonDeserializer<Double> {
@Override
public Double deserialize(JsonParser parser, DeserializationContext ctxt)
throws IOException, JsonProcessingException {
String doubleStr = parser.getText();
if (doubleStr.isEmpty() || doubleStr == null) {
return null;
}
return new Double(doubleStr);
}
}
我对每个字段进行注释:
@JsonDeserialize(using = DoubleDeserializer.class)
private Double partialPressureCO2;
@JsonDeserialize(using = DoubleDeserializer.class)
private Double partialPressureO2;
我注意到bean中的每个字段都会在处理DoubleDeserializer对象时创建它。这看起来非常低效。有什么我做错了吗?