mx.emite.sdk.clientes.Mapeador Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ef-sdk-java Show documentation
Show all versions of ef-sdk-java Show documentation
Este kit de consumo provee a los integradores de Apis de Java para construir software que consuma los diferentes servicios web publicados por Emite Facturacion
package mx.emite.sdk.clientes;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import lombok.extern.slf4j.Slf4j;
import mx.emite.sdk.errores.ApiException;
import mx.emite.sdk.errores.I_Api_Errores;
@Slf4j
public class Mapeador extends ObjectMapper{
/**
*
*/
private static final long serialVersionUID = -2070804639870254687L;
public Mapeador(){
enable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
disable(SerializationFeature.INDENT_OUTPUT);
}
public T deserializa(String json, Class clase) throws ApiException {
try{
return readValue(json, clase);
}
catch(Exception ex){
throw new ApiException(I_Api_Errores.DESERIALIZANDO,ex);
}
}
public T deserializa(final RespuestaHttp response, final Class clazz) throws ApiException{
if (response.isJson()) {
return deserializa(response.getBody(), clazz);
} else if (response.getBody() != null) {
log.debug("La respuesta no es Json: {}", response.getBody());
}
return null;
}
public String serializa(Object objeto) throws ApiException{
if(objeto==null)
return "";
try {
final String json = writeValueAsString(objeto);
return json;
} catch (JsonProcessingException e) {
throw new ApiException(I_Api_Errores.SERIALIZANDO,e);
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy