Class EncryptCertificateSerializer<T>

java.lang.Object
com.fasterxml.jackson.databind.JsonSerializer<T>
com.fasterxml.jackson.databind.ser.std.StdSerializer<T>
com.fasterxml.jackson.databind.ser.std.StdScalarSerializer<T>
com.bld.crypto.serializer.EncryptCertificateSerializer<T>
Type Parameters:
T - the type of the value to encrypt
All Implemented Interfaces:
com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitable, com.fasterxml.jackson.databind.jsonschema.SchemaAware, Serializable
Direct Known Subclasses:
EncryptAesSerializer, EncryptHmacSerializer, EncryptJksSerializer, EncryptPkcs12Serializer, EncryptPubKeySerializer

public abstract class EncryptCertificateSerializer<T> extends com.fasterxml.jackson.databind.ser.std.StdScalarSerializer<T>
Abstract Jackson StdScalarSerializer that encrypts a field value before writing it to the JSON output stream.

The serializer supports scalar types (Number, String), arrays, and collections. POJOs are first serialised to JSON using the injected ObjectMapper and then encrypted.

Concrete subclasses implement encryptValue(String) to supply the actual encryption algorithm (AES, RSA via JKS, or RSA public key).

See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from class com.fasterxml.jackson.databind.JsonSerializer

    com.fasterxml.jackson.databind.JsonSerializer.None
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected com.fasterxml.jackson.databind.ObjectMapper
    Jackson ObjectMapper used to serialise POJO values to JSON before encryption.

    Fields inherited from class com.fasterxml.jackson.databind.ser.std.StdSerializer

    _handledType
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Constructs a new serializer for the given type.
    protected
    EncryptCertificateSerializer(Class<T> t, com.fasterxml.jackson.databind.ObjectMapper objMapper)
    Constructs a new serializer for the given type with an explicit ObjectMapper.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected abstract String
    Encrypts the given plain-text string.
    void
    serialize(T value, com.fasterxml.jackson.core.JsonGenerator gen, com.fasterxml.jackson.databind.SerializerProvider provider)
    Serialises and encrypts the value, writing the result as a JSON string (or JSON array when the value is a Collection or array).

    Methods inherited from class com.fasterxml.jackson.databind.ser.std.StdScalarSerializer

    acceptJsonFormatVisitor, getSchema, serializeWithType

    Methods inherited from class com.fasterxml.jackson.databind.ser.std.StdSerializer

    _neitherNull, _nonEmpty, createSchemaNode, createSchemaNode, findAnnotatedContentSerializer, findContextualConvertingSerializer, findConvertingContentSerializer, findFormatFeature, findFormatOverrides, findIncludeOverrides, findPropertyFilter, getSchema, handledType, isDefaultSerializer, visitArrayFormat, visitArrayFormat, visitFloatFormat, visitIntFormat, visitIntFormat, visitStringFormat, visitStringFormat, wrapAndThrow, wrapAndThrow

    Methods inherited from class com.fasterxml.jackson.databind.JsonSerializer

    getDelegatee, isEmpty, isEmpty, isUnwrappingSerializer, properties, replaceDelegatee, unwrappingSerializer, usesObjectId, withFilterId, withIgnoredProperties

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • objMapper

      @Autowired protected com.fasterxml.jackson.databind.ObjectMapper objMapper
      Jackson ObjectMapper used to serialise POJO values to JSON before encryption.
  • Constructor Details

    • EncryptCertificateSerializer

      protected EncryptCertificateSerializer(Class<T> t)
      Constructs a new serializer for the given type. The ObjectMapper will be injected by Spring.
      Parameters:
      t - the handled value type
    • EncryptCertificateSerializer

      protected EncryptCertificateSerializer(Class<T> t, com.fasterxml.jackson.databind.ObjectMapper objMapper)
      Constructs a new serializer for the given type with an explicit ObjectMapper. Use this constructor when Spring injection is not available (e.g., in tests).
      Parameters:
      t - the handled value type
      objMapper - the Jackson ObjectMapper instance
  • Method Details

    • serialize

      public void serialize(T value, com.fasterxml.jackson.core.JsonGenerator gen, com.fasterxml.jackson.databind.SerializerProvider provider) throws IOException
      Serialises and encrypts the value, writing the result as a JSON string (or JSON array when the value is a Collection or array).
      Specified by:
      serialize in class com.fasterxml.jackson.databind.ser.std.StdSerializer<T>
      Parameters:
      value - the value to encrypt and serialise; nothing is written if null
      gen - the Jackson JsonGenerator
      provider - the serialiser provider
      Throws:
      IOException - if a JSON I/O error occurs
    • encryptValue

      protected abstract String encryptValue(String word)
      Encrypts the given plain-text string. Concrete subclasses supply the algorithm and key selection logic.
      Parameters:
      word - the plain-text string to encrypt
      Returns:
      the encrypted, Base64-encoded string