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:
  • Field Details

  • Constructor Details

  • Method Details

    • handledType

      public Class<Object> handledType()
      Overrides:
      handledType in class com.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:
      createContextual in interface com.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:
      serialize in class com.fasterxml.jackson.databind.JsonSerializer<Object>
      Throws:
      IOException
      com.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

      public static List<String> getNeededLanguageList()
    • getCurrentUserLang

      public static String getCurrentUserLang()