1
0
mirror of https://github.com/SKCraft/Launcher.git synced 2024-11-27 12:46:22 +01:00

Add HttpRequest.asJson(TypeReference type).

This commit is contained in:
sk89q 2015-07-27 19:51:59 -07:00
parent a31e07d1d7
commit a3ad521e38

View File

@ -6,6 +6,7 @@
package com.skcraft.launcher.util;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.skcraft.concurrency.ProgressObservable;
import lombok.Getter;
@ -452,6 +453,7 @@ public class HttpRequest implements Closeable, ProgressObservable {
* Return the result as an instance of the given class that has been
* deserialized from a JSON payload.
*
* @param cls the class
* @return the object
* @throws java.io.IOException on I/O error
*/
@ -459,6 +461,18 @@ public class HttpRequest implements Closeable, ProgressObservable {
return mapper.readValue(asString("UTF-8"), cls);
}
/**
* Return the result as an instance of the given type that has been
* deserialized from a JSON payload.
*
* @param type the type reference
* @return the object
* @throws java.io.IOException on I/O error
*/
public <T> T asJson(TypeReference type) throws IOException {
return mapper.readValue(asString("UTF-8"), type);
}
/**
* Return the result as an instance of the given class that has been
* deserialized from a XML payload.