// Path: common/src/main/java/cz/gopay/api/v3/model/APIError.java
// @XmlRootElement(name = "error")
// public class APIError {
// 
//     @XmlElement(name = "date_issued")
//     @XmlJavaTypeAdapter(GPTimestampAdapter.class)
//     private Date dateIssued;
// 
//     @XmlElement(name = "errors",required = true)
//     private List<ErrorElement> errorMessages;
// 
//     public APIError() {
//     }
// 
//     public APIError(Date dateIssued) {
//         this.dateIssued = dateIssued;
//     }
// 
//     public static APIError create() {
//         return new APIError(new Date());
//     }
// 
//     public APIError addError(String errorName, int errorCode, String message,
//             String description) {
//         if (errorMessages == null) {
//             errorMessages = new ArrayList<>();
//         }
// 
//         errorMessages.add(new ErrorElement(errorName, errorCode, message, description));
// 
//         return this;
//     }
// 
//     public APIError addError(String errorName, int errorCode, String field,
//             String message, String description) {
//         if (errorMessages == null) {
//             errorMessages = new ArrayList<>();
//         }
// 
//         errorMessages.add(new ErrorElement(errorName, errorCode, field, message, description));
//         return this;
//     }
// 
//     public Date getDateIssued() {
//         return dateIssued;
//     }
// 
//     public void setDateIssued(Date dateOccured) {
//         this.dateIssued = dateOccured;
//     }
// 
//     public List<ErrorElement> getErrorMessages() {
//         return errorMessages;
//     }
// 
//     public void setErrorMessages(List<ErrorElement> errors) {
//         this.errorMessages = errors;
//     }
// 
// }


import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.deser.DeserializationProblemHandler;
import com.fasterxml.jackson.databind.type.TypeFactory;
import com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector;
import cz.gopay.api.v3.model.APIError;
import java.io.IOException;
import javax.ws.rs.WebApplicationException;
import org.apache.http.HttpResponse;
import org.apache.http.client.fluent.Response;
import org.apache.http.util.EntityUtils;
import org.apache.logging.log4j.Logger;

package cz.gopay.api.v3.impl.apacheclient;


/**
 *
 * @author Frantisek Sichinger
 */
public class AbstractImpl {
    
    protected static final String IMPLEMENTATION_NAME = "${project.artifactId}";
    protected static final String VERSION = "${project.artifactId}";
    
    protected static final String AUTHORIZATION = "Authorization";
    protected static final String SCOPE = "scope";
    protected static final String GRANT_TYPE = "grant_type";
    protected static final String CONTENT_TYPE = "Content-Type";
    protected static final String ACCEPT = "Accept";
    protected static final String USER_AGENT = "User-Agent";

    protected String apiUrl;
    private final ObjectMapper mapper;
    protected Logger logger;

    public AbstractImpl(String apiUrl) {
        this.apiUrl = apiUrl;
        mapper = new ObjectMapper();
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        mapper.setAnnotationIntrospector(new JaxbAnnotationIntrospector(TypeFactory.defaultInstance()));
    }

    protected <T> T unMarshall(Response response, Class<T> entity) {
        String json = null;
        try {
            HttpResponse httpresponse = response.returnResponse();
            json = entityToString(httpresponse);
            JsonNode tree = mapper.readTree(json);
// Path: common/src/main/java/cz/gopay/api/v3/model/APIError.java
// @XmlRootElement(name = "error")
// public class APIError {
// 
//     @XmlElement(name = "date_issued")
//     @XmlJavaTypeAdapter(GPTimestampAdapter.class)
//     private Date dateIssued;
// 
//     @XmlElement(name = "errors",required = true)
//     private List<ErrorElement> errorMessages;
// 
//     public APIError() {
//     }
// 
//     public APIError(Date dateIssued) {
//         this.dateIssued = dateIssued;
//     }
// 
//     public static APIError create() {
//         return new APIError(new Date());
//     }
// 
//     public APIError addError(String errorName, int errorCode, String message,
//             String description) {
//         if (errorMessages == null) {
//             errorMessages = new ArrayList<>();
//         }
// 
//         errorMessages.add(new ErrorElement(errorName, errorCode, message, description));
// 
//         return this;
//     }
// 
//     public APIError addError(String errorName, int errorCode, String field,
//             String message, String description) {
//         if (errorMessages == null) {
//             errorMessages = new ArrayList<>();
//         }
// 
//         errorMessages.add(new ErrorElement(errorName, errorCode, field, message, description));
//         return this;
//     }
// 
//     public Date getDateIssued() {
//         return dateIssued;
//     }
// 
//     public void setDateIssued(Date dateOccured) {
//         this.dateIssued = dateOccured;
//     }
// 
//     public List<ErrorElement> getErrorMessages() {
//         return errorMessages;
//     }
// 
//     public void setErrorMessages(List<ErrorElement> errors) {
//         this.errorMessages = errors;
//     }
// 
// }


// Path: apache-http-client/src/main/java/cz/gopay/api/v3/impl/apacheclient/AbstractImpl.java
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.deser.DeserializationProblemHandler;
import com.fasterxml.jackson.databind.type.TypeFactory;
import com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector;
import cz.gopay.api.v3.model.APIError;
import java.io.IOException;
import javax.ws.rs.WebApplicationException;
import org.apache.http.HttpResponse;
import org.apache.http.client.fluent.Response;
import org.apache.http.util.EntityUtils;
import org.apache.logging.log4j.Logger;


package cz.gopay.api.v3.impl.apacheclient;


/**
 *
 * @author Frantisek Sichinger
 */
public class AbstractImpl {
    
    protected static final String IMPLEMENTATION_NAME = "${project.artifactId}";
    protected static final String VERSION = "${project.artifactId}";
    
    protected static final String AUTHORIZATION = "Authorization";
    protected static final String SCOPE = "scope";
    protected static final String GRANT_TYPE = "grant_type";
    protected static final String CONTENT_TYPE = "Content-Type";
    protected static final String ACCEPT = "Accept";
    protected static final String USER_AGENT = "User-Agent";

    protected String apiUrl;
    private final ObjectMapper mapper;
    protected Logger logger;

    public AbstractImpl(String apiUrl) {
        this.apiUrl = apiUrl;
        mapper = new ObjectMapper();
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        mapper.setAnnotationIntrospector(new JaxbAnnotationIntrospector(TypeFactory.defaultInstance()));
    }

    protected <T> T unMarshall(Response response, Class<T> entity) {
        String json = null;
        try {
            HttpResponse httpresponse = response.returnResponse();
            json = entityToString(httpresponse);
            JsonNode tree = mapper.readTree(json);
            APIError error = mapper.treeToValue(tree, APIError.class);