com.realcomp.consul.ConsulResponse Maven / Gradle / Ivy
package com.realcomp.consul;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import javax.xml.bind.DatatypeConverter;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.*;
/**
* Unmarshalls the JSON and Base64 encoded responses from the Consul server.
*/
public class ConsulResponse{
private static final ObjectMapper JACKSON = new ObjectMapper();
private static final TypeReference>> CONSUL_METADATA_TYPE
= new TypeReference>>(){};
private static final TypeReference> CONSUL_KEYS_TYPE
= new TypeReference>(){};
public static List parseList(Optional json) throws IOException{
return json.isPresent() ? parseList(json.get()) : Collections.EMPTY_LIST;
}
public static List parseList(String json) throws IOException{
Objects.requireNonNull(json);
return JACKSON.readValue(json, CONSUL_KEYS_TYPE);
}
public static Optional parseSingleValue(Optional json) throws IOException{
return json.isPresent() ? parseSingleValue(json.get()) : Optional.empty();
}
public static Optional parseSingleValue(String json) throws IOException{
Objects.requireNonNull(json);
List