本文整理了Java中feign.Util.emptyValueOf()
方法的一些代码示例,展示了Util.emptyValueOf()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.emptyValueOf()
方法的具体详情如下:
包路径:feign.Util
类名称:Util
方法名:emptyValueOf
[英]This returns well known empty values for well-known java types. This returns null for types not in the following list.
When Feign.Builder#decode404(), you'll need to teach decoders a default empty value for a type. This method cheaply supports typical types by only looking at the raw type (vs type hierarchy). Decorate for sophistication.
[中]这将返回已知java类型的已知空值。对于不在以下列表中的类型,这将返回null。
*[Bb]oolean
*字节[]
*收藏
*迭代器
*名单
*地图
*设定
假装的时候。在Builder#decode404()中,您需要将类型的默认空值教给解码器。这种方法只需查看原始类型(vs类型层次结构),就可以廉价地支持典型类型。装饰得更精致。
代码示例来源:origin: com.netflix.feign/feign-jackson
@Override
public Object decode(Response response, Type type) throws IOException {
if (response.status() == 404) return Util.emptyValueOf(type);
if (response.body() == null) return null;
Reader reader = response.body().asReader();
if (!reader.markSupported()) {
reader = new BufferedReader(reader, 1);
}
try {
// Read the first byte to see if we have any data
reader.mark(1);
if (reader.read() == -1) {
return null; // Eagerly returning null avoids "No content to map due to end-of-input"
}
reader.reset();
return mapper.readValue(reader, mapper.constructType(type));
} catch (RuntimeJsonMappingException e) {
if (e.getCause() != null && e.getCause() instanceof IOException) {
throw IOException.class.cast(e.getCause());
}
throw e;
}
}
}
代码示例来源:origin: com.netflix.feign/feign-core
@Override
public Object decode(Response response, Type type) throws IOException {
if (response.status() == 404) return Util.emptyValueOf(type);
if (response.body() == null) return null;
if (byte[].class.equals(type)) {
return Util.toByteArray(response.body().asInputStream());
}
return super.decode(response, type);
}
}
代码示例来源:origin: io.github.openfeign/feign-jaxb
@Override
public Object decode(Response response, Type type) throws IOException {
if (response.status() == 404 || response.status() == 204)
return Util.emptyValueOf(type);
if (response.body() == null)
return null;
代码示例来源:origin: io.github.openfeign/feign-gson
@Override
public Object decode(Response response, Type type) throws IOException {
if (response.status() == 404)
return Util.emptyValueOf(type);
if (response.body() == null)
return null;
Reader reader = response.body().asReader();
try {
return gson.fromJson(reader, type);
} catch (JsonIOException e) {
if (e.getCause() != null && e.getCause() instanceof IOException) {
throw IOException.class.cast(e.getCause());
}
throw e;
} finally {
ensureClosed(reader);
}
}
}
内容来源于网络,如有侵权,请联系作者删除!