id.unum.facade.rest.serialization.PresentationRequestRepoDtoDeserializer Maven / Gradle / Ivy
The newest version!
package id.unum.facade.rest.serialization;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.util.JsonFormat;
import id.unum.protos.presentationRequestEnriched.v1.PresentationRequestRepoDto;
import lombok.extern.log4j.Log4j2;
import java.lang.reflect.Type;
@Log4j2
public class PresentationRequestRepoDtoDeserializer implements JsonDeserializer {
@Override
public PresentationRequestRepoDto deserialize(JsonElement jsonElement, Type type,
JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
PresentationRequestRepoDto.Builder builder = PresentationRequestRepoDto.newBuilder();
try {
JsonFormat.parser().ignoringUnknownFields().merge(jsonElement.toString(), builder);
} catch (InvalidProtocolBufferException e) {
log.error("Issue deserializing PresentationRequestRepoDto: " + e.getMessage());
e.printStackTrace();
}
return builder.build();
}
}