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