【发布时间】:2020-01-29 00:27:51
【问题描述】:
我正在尝试编写通用 Json 反序列化器,如下所示,
public static <T> BiFunction<String, Class<T>, T> jsonDeSerializer() {
return (o, c) -> {
try {
return mapper.readValue(o, c);
} catch (IOException e) {
logger.error("json.parse.error object.type={}", o.getClass().getSimpleName(), e);
throw new JsonProcessingEx(e);
}
};
}
当我试图打电话时,我得到了
error: incompatible types: Class<MLAdhocResponseVO> cannot be converted to Class<Object>
MLAdhocResponseVO response = JsonUtils.jsonDeSerializer().apply("{}", MLAdhocResponseVO.class);
我只想写一个 BiFunction,它根据提供的类返回 Object,而不需要任何类型转换。
【问题讨论】: