id.unum.facade.rest.serialization.PresentationRequestSerializer Maven / Gradle / Ivy
The newest version!
package id.unum.facade.rest.serialization;
import com.google.gson.*;
import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.util.JsonFormat;
import id.unum.protos.presentationRequest.v1.PresentationRequest;
import lombok.extern.log4j.Log4j2;
import java.lang.reflect.Type;
@Log4j2
public class PresentationRequestSerializer implements JsonSerializer {
@Override
public JsonElement serialize(PresentationRequest presentationRequest, Type type, JsonSerializationContext jsonSerializationContext) {
try {
JsonElement output =
JsonParser.parseString(JsonFormat.printer().omittingInsignificantWhitespace().print(presentationRequest));
return output.getAsJsonObject();
} catch (InvalidProtocolBufferException e) {
log.error("Error serializing PresentationRequest: " + e.getMessage());
e.printStackTrace();
}
return null;
}
}