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

io.github.juniqlim.apicall.http.ResponseBodyParser Maven / Gradle / Ivy

There is a newer version: 0.0.14
Show newest version
package io.github.juniqlim.apicall.http;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;

/**
 * interface
 */
public class ResponseBodyParser {
    private final ObjectMapper objectMapper;

    private ResponseBodyParser(ObjectMapper objectMapper) {
        this.objectMapper = objectMapper;
    }

    public static ResponseBodyParser of(ObjectMapper objectMapper) {
        objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        return new ResponseBodyParser(objectMapper);
    }

    public  T parse(String result, Class T) {
        try {
            return objectMapper.readValue(result, T);
        } catch (IOException e) {
            throw new RuntimeException("json parse error: " + e.getMessage());
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy