com.safelayer.rap.json.X509CertificateSerializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pki-connector-restapi Show documentation
Show all versions of pki-connector-restapi Show documentation
The PKI Connector RESTAPI is a library that helps developing new PKI Connectors for TrustedX
The newest version!
package com.safelayer.rap.json;
import java.io.IOException;
import java.security.cert.CertificateEncodingException;
import java.security.cert.X509Certificate;
import org.apache.commons.codec.binary.Base64;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
public class X509CertificateSerializer extends JsonSerializer {
@Override
public void serialize(X509Certificate cert, JsonGenerator generator, SerializerProvider serializerProvider)
throws IOException, JsonProcessingException {
try {
generator.writeString(Base64.encodeBase64String(cert.getEncoded()));
}
catch (CertificateEncodingException e) {
throw new JsonException(e);
}
}
}