Class OrderedSetSerializer<T>

java.lang.Object
com.fasterxml.jackson.databind.JsonSerializer<Set<T>>
io.fliqa.client.interledger.serializer.OrderedSetSerializer<T>
Type Parameters:
T - the type of elements contained in the set to be serialized
All Implemented Interfaces:
com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitable

public class OrderedSetSerializer<T> extends com.fasterxml.jackson.databind.JsonSerializer<Set<T>>
A custom serializer for Set collections that serializes the elements in a deterministic order based on their string representations.

The OrderedSetSerializer ensures that the serialization output for a Set is consistent irrespective of the initial ordering of the elements within the set. It accomplishes this by converting each element in the set to its toString() representation, sorting these string representations in natural order, and then writing them as a JSON array.

This serializer is useful in scenarios where consistent JSON output is required, such as when generating hashes, for debugging purposes, or for API clients requiring deterministic outputs for identical data sets.

See Also:
  • JsonSerializer
  • Nested Class Summary

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

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

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    serialize(Set<T> value, com.fasterxml.jackson.core.JsonGenerator gen, com.fasterxml.jackson.databind.SerializerProvider serializers)
     

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

    acceptJsonFormatVisitor, getDelegatee, handledType, isEmpty, isEmpty, isUnwrappingSerializer, properties, replaceDelegatee, serializeWithType, unwrappingSerializer, usesObjectId, withFilterId, withIgnoredProperties

    Methods inherited from class java.lang.Object

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

    • OrderedSetSerializer

      public OrderedSetSerializer()
  • Method Details

    • serialize

      public void serialize(Set<T> value, com.fasterxml.jackson.core.JsonGenerator gen, com.fasterxml.jackson.databind.SerializerProvider serializers) throws IOException
      Specified by:
      serialize in class com.fasterxml.jackson.databind.JsonSerializer<Set<T>>
      Throws:
      IOException