Files
2026-11-21 17:07:18 -05:00

88 lines
2.2 KiB
Java

/* */ package kong.unirest.cosmetics;
/* */
/* */ import java.util.Optional;
/* */ import java.util.function.Function;
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ class ObjectResponse<T>
/* */ extends BaseResponse<T>
/* */ {
/* */ private final T body;
/* */ private final ObjectMapper om;
/* */ private String rawBody;
/* */
/* */ ObjectResponse(ObjectMapper om, RawResponse response, Class<? extends T> to) {
/* 38 */ super(response);
/* 39 */ this.om = om;
/* 40 */ this
/* */
/* 42 */ .body = readBody(response).<T>map(s -> getBody(s, ())).orElse(null);
/* */ }
/* */
/* */ ObjectResponse(ObjectMapper om, RawResponse response, GenericType<? extends T> to) {
/* 46 */ super(response);
/* 47 */ this.om = om;
/* 48 */ this
/* */
/* 50 */ .body = readBody(response).<T>map(s -> getBody(s, ())).orElse(null);
/* */ }
/* */
/* */ private Optional<String> readBody(RawResponse response) {
/* 54 */ if (!response.hasContent()) {
/* 55 */ return Optional.empty();
/* */ }
/* 57 */ String s = response.getContentAsString();
/* 58 */ if (response.getStatus() >= 400) {
/* 59 */ this.rawBody = s;
/* */ }
/* 61 */ return Optional.of(s);
/* */ }
/* */
/* */ private T getBody(String b, Function<String, T> func) {
/* */ try {
/* 66 */ return func.apply(b);
/* 67 */ } catch (RuntimeException e) {
/* 68 */ setParsingException(b, e);
/* 69 */ return null;
/* */ }
/* */ }
/* */
/* */
/* */ public T getBody() {
/* 75 */ return this.body;
/* */ }
/* */
/* */
/* */ protected String getRawBody() {
/* 80 */ return this.rawBody;
/* */ }
/* */ }
/* Location: C:\Users\Xiao\Downloads\MinehutCosmetics.jar!\kon\\unirest\cosmetics\ObjectResponse.class
* Java compiler version: 11 (55.0)
* JD-Core Version: 1.1.3
*/