Class StringSerializer

  • All Implemented Interfaces:
    Serializer<java.lang.String>

    public class StringSerializer
    extends java.lang.Object
    implements Serializer<java.lang.String>
    A Serializer implementation for converting String objects into byte arrays using a specified charset.

    This class provides a thread-safe mechanism for serializing strings. By default, it uses UTF-8 encoding if no specific charset is provided during construction.

    Example Usage

    
     // Using the default UTF-8 charset
     Serializer<String> serializer = new StringSerializer();
     byte[] bytes = serializer.serialize("Hello, World!");
    
     // Using a custom charset
     Serializer<String> serializerWithCharset = new StringSerializer(StandardCharsets.ISO_8859_1);
     byte[] customEncodedBytes = serializerWithCharset.serialize("Sample Text");
     
    Since:
    1.0.0
    Author:
    Mercy
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      byte[] serialize​(java.lang.String source)  
      • Methods inherited from class java.lang.Object

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

      • StringSerializer

        public StringSerializer()
      • StringSerializer

        public StringSerializer​(java.nio.charset.Charset charset)
    • Method Detail

      • serialize

        public byte[] serialize​(java.lang.String source)
                         throws java.io.IOException
        Specified by:
        serialize in interface Serializer<java.lang.String>
        Throws:
        java.io.IOException