All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hashicorp.nomad.javasdk.JsonParser Maven / Gradle / Ivy

There is a newer version: 0.11.3.0
Show newest version
package com.hashicorp.nomad.javasdk;

import com.fasterxml.jackson.databind.JavaType;

import java.io.IOException;

/**
 * Wraps a Jackson ObjectMapper to parse values of a specific type.
 * @param 
 */
class JsonParser implements ValueExtractor {
    private final JavaType responseEntityType;

    JsonParser(JavaType responseEntityType) {
        this.responseEntityType = responseEntityType;
    }

    /**
     * Parses a value from the JSON string.
     */
    @Override
    public T extractValue(String json) throws ResponseParsingException {
        try {
            return NomadJson.deserialize(json, responseEntityType);
        } catch (IOException e) {
            throw new ResponseParsingException(
                    "Unable to parse " + responseEntityType + " from response body JSON: " + json,
                    json,
                    e);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy