com.logicommerce.sdk.resources.ResponseParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sdk Show documentation
Show all versions of sdk Show documentation
SDK for developing Logicommerce plugins.
package com.logicommerce.sdk.resources;
import com.logicommerce.utilities.JsonConverterException;
import com.logicommerce.utilities.JsonMapper;
public class ResponseParser {
private ResponseParser() {}
public static T parse(int statusCode, String body, Class type) throws ResponseException {
if (statusCode > 399) {
throw new ResponseException(body);
}
if (body == null || body.isBlank()) {
return null;
}
JsonMapper jsonMapper = new JsonMapper<>(type);
try {
return jsonMapper.fromJson(body);
} catch (JsonConverterException e) {
throw new ResponseException(body, e);
}
}
}