
io.github.juniqlim.apicall.http.ResponseBodyParser Maven / Gradle / Ivy
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 extends T> 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