Class CustomJsonSerializer
java.lang.Object
com.fasterxml.jackson.databind.JsonSerializer<Object>
com.jalios.jcms.restv2.serializer.CustomJsonSerializer
- All Implemented Interfaces:
com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitable,com.fasterxml.jackson.databind.ser.ContextualSerializer
public class CustomJsonSerializer
extends com.fasterxml.jackson.databind.JsonSerializer<Object>
implements com.fasterxml.jackson.databind.ser.ContextualSerializer
Custom JSON serializer providing advanced control over object serialization.
This serializer extends Jackson's JsonSerializer and supports contextual
serialization via ContextualSerializer. It is designed to handle complex
serialization scenarios including:
- Dynamic field selection based on a configured select list
- Multi-language support for serialized content
- Controlled serialization depth to avoid deep object graphs
- Custom serialization logic for specific domain objects (e.g. Data, Member, Workflow)
- Access control checks to prevent unauthorized data exposure
- Injection of additional computed fields via custom functions
The serializer relies on a SerializationCustomConfiguration instance
to drive its behavior (e.g. selected fields, max depth, user context).
Thread-local variables are used internally to maintain serialization context
(such as current depth, selected fields, and language preferences) across nested calls.
These must be cleared after use via clearThreadLocals() to prevent memory leaks.
This serializer also supports contextualization per property, allowing access to the current field name during serialization.
- 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 -
Constructor Summary
ConstructorsConstructorDescriptionCustomJsonSerializer(SerializationCustomConfiguration serializeConfig) CustomJsonSerializer(SerializationCustomConfiguration serializeConfig, String fieldName) -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcom.fasterxml.jackson.databind.JsonSerializer<?> createContextual(com.fasterxml.jackson.databind.SerializerProvider prov, com.fasterxml.jackson.databind.BeanProperty property) static Stringcom.fasterxml.jackson.databind.JsonSerializer<Object> getDefaultSerializer(com.fasterxml.jackson.databind.SerializerProvider serializerProvider) voidserialize(Object obj, com.fasterxml.jackson.core.JsonGenerator jgen, com.fasterxml.jackson.databind.SerializerProvider serializerProvider) Methods inherited from class com.fasterxml.jackson.databind.JsonSerializer
acceptJsonFormatVisitor, getDelegatee, isEmpty, isEmpty, isUnwrappingSerializer, properties, replaceDelegatee, serializeWithType, unwrappingSerializer, usesObjectId, withFilterId, withIgnoredProperties
-
Field Details
-
currentData
-
-
Constructor Details
-
CustomJsonSerializer
-
CustomJsonSerializer
-
-
Method Details
-
handledType
- Overrides:
handledTypein classcom.fasterxml.jackson.databind.JsonSerializer<Object>
-
createContextual
public com.fasterxml.jackson.databind.JsonSerializer<?> createContextual(com.fasterxml.jackson.databind.SerializerProvider prov, com.fasterxml.jackson.databind.BeanProperty property) throws com.fasterxml.jackson.databind.JsonMappingException - Specified by:
createContextualin interfacecom.fasterxml.jackson.databind.ser.ContextualSerializer- Throws:
com.fasterxml.jackson.databind.JsonMappingException
-
serialize
public void serialize(Object obj, com.fasterxml.jackson.core.JsonGenerator jgen, com.fasterxml.jackson.databind.SerializerProvider serializerProvider) throws IOException, com.fasterxml.jackson.core.JsonProcessingException - Specified by:
serializein classcom.fasterxml.jackson.databind.JsonSerializer<Object>- Throws:
IOExceptioncom.fasterxml.jackson.core.JsonProcessingException
-
getDefaultSerializer
public com.fasterxml.jackson.databind.JsonSerializer<Object> getDefaultSerializer(com.fasterxml.jackson.databind.SerializerProvider serializerProvider) -
clearThreadLocals
public static void clearThreadLocals() -
getNeededLanguageList
-
getCurrentUserLang
-