Package com.bld.crypto.serializer
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
FieldsModifier and TypeFieldDescriptionprotected com.fasterxml.jackson.databind.ObjectMapperJacksonObjectMapperused to serialise POJO values to JSON before encryption.Fields inherited from class com.fasterxml.jackson.databind.ser.std.StdSerializer
_handledType -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConstructs a new serializer for the given type.protectedEncryptCertificateSerializer(Class<T> t, com.fasterxml.jackson.databind.ObjectMapper objMapper) Constructs a new serializer for the given type with an explicitObjectMapper. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract StringencryptValue(String word) Encrypts the given plain-text string.voidserialize(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 aCollectionor array).Methods inherited from class com.fasterxml.jackson.databind.ser.std.StdScalarSerializer
acceptJsonFormatVisitor, getSchema, serializeWithTypeMethods 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, wrapAndThrowMethods inherited from class com.fasterxml.jackson.databind.JsonSerializer
getDelegatee, isEmpty, isEmpty, isUnwrappingSerializer, properties, replaceDelegatee, unwrappingSerializer, usesObjectId, withFilterId, withIgnoredProperties
-
Field Details
-
objMapper
@Autowired protected com.fasterxml.jackson.databind.ObjectMapper objMapperJacksonObjectMapperused to serialise POJO values to JSON before encryption.
-
-
Constructor Details
-
EncryptCertificateSerializer
Constructs a new serializer for the given type. TheObjectMapperwill 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 explicitObjectMapper. Use this constructor when Spring injection is not available (e.g., in tests).- Parameters:
t- the handled value typeobjMapper- the JacksonObjectMapperinstance
-
-
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 aCollectionor array).- Specified by:
serializein classcom.fasterxml.jackson.databind.ser.std.StdSerializer<T>- Parameters:
value- the value to encrypt and serialise; nothing is written ifnullgen- the JacksonJsonGeneratorprovider- the serialiser provider- Throws:
IOException- if a JSON I/O error occurs
-
encryptValue
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
-