Class StringDeserializer

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

    public class StringDeserializer
    extends java.lang.Object
    implements Deserializer<java.lang.String>
    A Deserializer implementation for converting byte arrays into String instances.

    This class uses a specified Charset to decode the byte array into a string. If no charset is provided, it defaults to using UTF-8.

    Thread Safety

    This implementation is thread-safe as it does not maintain any internal state that may be modified after construction.

    Example Usage

    
     // Using default charset (UTF-8)
     Deserializer<String> deserializer = new StringDeserializer();
     String result = deserializer.deserialize("Hello, World!".getBytes(StandardCharsets.UTF_8));
     System.out.println(result); // Output: Hello, World!
     
    
     // Using custom charset (e.g., ISO-8859-1)
     Deserializer<String> deserializer = new StringDeserializer(StandardCharsets.ISO_8859_1);
     String result = deserializer.deserialize("Sample".getBytes(StandardCharsets.ISO_8859_1));
     System.out.println(result); // Output: Sample
     
    Since:
    1.0.0
    Author:
    Mercy
    See Also:
    Deserializer, Serializer
    • Method Summary

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

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

      • StringDeserializer

        public StringDeserializer()
      • StringDeserializer

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

      • deserialize

        public java.lang.String deserialize​(byte[] bytes)
                                     throws java.io.IOException
        Specified by:
        deserialize in interface Deserializer<java.lang.String>
        Throws:
        java.io.IOException