Class JSONToolsImpl

  • All Implemented Interfaces:
    com.anaptecs.jeaf.json.api.JSONTools

    @ToolsImplementation(toolsInterface=com.anaptecs.jeaf.json.api.JSONTools.class)
    public class JSONToolsImpl
    extends java.lang.Object
    implements com.anaptecs.jeaf.json.api.JSONTools
    Class provides an implementation of JEAF JSON Tools
    Author:
    JEAF Development Team
    • Field Summary

      • Fields inherited from interface com.anaptecs.jeaf.json.api.JSONTools

        JSON_BASE_PATH, JSON_TOOLS
    • Constructor Summary

      Constructors 
      Constructor Description
      JSONToolsImpl()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      com.fasterxml.jackson.databind.ObjectMapper getDefaultObjectMapper()
      Method returns a JSON ObjectMapper that is configured as defined using ObjectMapperConfig and ModuleFactory.
      <T> T read​(byte[] pBytes, com.anaptecs.jeaf.json.api.ObjectType pResultType)
      Method deserializes the passed byte array into an object of the passed type.
      <T> T read​(byte[] pBytes, java.lang.Class<T> pResultType)
      Method deserializes the passed byte array into an object of the passed type.
      <T> T read​(java.io.File pFile, com.anaptecs.jeaf.json.api.ObjectType pResultType)
      Method deserializes the data from the passed file into an object of the passed type.
      <T> T read​(java.io.File pFile, java.lang.Class<T> pResultType)
      Method deserializes the data from the passed file into an object of the passed type.
      <T> T read​(java.io.InputStream pInputStream, com.anaptecs.jeaf.json.api.ObjectType pResultType)
      Method deserializes the data of passed stream into an object of the passed type.
      <T> T read​(java.io.InputStream pInputStream, java.lang.Class<T> pResultType)
      Method deserializes the data of passed stream into an object of the passed type.
      <T> T read​(java.io.Reader pReader, com.anaptecs.jeaf.json.api.ObjectType pResultType)
      Method deserializes the data from the passed reader into an object of the passed type.
      <T> T read​(java.io.Reader pReader, java.lang.Class<T> pResultType)
      Method deserializes the data from the passed reader into an object of the passed type.
      <T> T read​(java.lang.String pString, com.anaptecs.jeaf.json.api.ObjectType pResultType)
      Method deserializes the passed string into an object of the passed type.
      <T> T read​(java.lang.String pString, java.lang.Class<T> pResultType)
      Method deserializes the passed string into an object of the passed type.
      <T> T readToCollection​(byte[] pBytes, java.lang.Class<? extends java.util.Collection> pCollectionType, java.lang.Class<?> pResultType)
      Method deserializes the passed string into a List of objects of the passed type.
      <T> T readToCollection​(java.io.File pFile, java.lang.Class<? extends java.util.Collection> pCollectionType, java.lang.Class<?> pResultType)
      Method deserializes the data from the passed file into a List of objects of the passed type.
      <T> T readToCollection​(java.io.InputStream pInputStream, java.lang.Class<? extends java.util.Collection> pCollectionType, java.lang.Class<?> pResultType)
      Method deserializes the data of passed stream into a List of objects of the passed type.
      <T> T readToCollection​(java.io.Reader pReader, java.lang.Class<? extends java.util.Collection> pCollectionType, java.lang.Class<?> pResultType)
      Method deserializes the data from the passed reader into a List of objects of the passed type.
      <T> T readToCollection​(java.lang.String pString, java.lang.Class<? extends java.util.Collection> pCollectionType, java.lang.Class<?> pResultType)
      Method deserializes the passed string into a List of objects of the passed type.
      void writeObject​(java.lang.Object pObject, java.io.File pFile)
      Method serializes the passed object to the passed file.
      void writeObject​(java.lang.Object pObject, java.io.OutputStream pOutputStream)
      Method serializes the passed object to the passed stream.
      void writeObject​(java.lang.Object pObject, java.io.Writer pWriter)
      Method serializes the passed object to the passed writer.
      void writeObjects​(java.util.Collection<?> pObjects, java.io.File pFile, java.lang.Class<?> pObjectType)
      Method serializes the passed Collection to the passed file.
      void writeObjects​(java.util.Collection<?> pObjects, java.io.OutputStream pOutputStream, java.lang.Class<?> pObjectType)
      Method serializes the passed Collection to the passed stream.
      void writeObjects​(java.util.Collection<?> pObjects, java.io.Writer pWriter, java.lang.Class<?> pObjectType)
      Method serializes the passed Collection to the passed writer.
      byte[] writeObjectsToBytes​(java.util.Collection<?> pObjects, java.lang.Class<?> pObjectType)
      Method serializes the passed Collection as byte array.
      java.lang.String writeObjectsToString​(java.util.Collection<?> pObjects, java.lang.Class<?> pObjectType)
      Method serializes the passed Collection as string.
      byte[] writeObjectToBytes​(java.lang.Object pObject)
      Method serializes the passed object as byte array.
      java.lang.String writeObjectToString​(java.lang.Object pObject)
      Method serializes the passed object as string.
      • Methods inherited from class java.lang.Object

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

      • JSONToolsImpl

        public JSONToolsImpl()
    • Method Detail

      • getDefaultObjectMapper

        public com.fasterxml.jackson.databind.ObjectMapper getDefaultObjectMapper()
        Method returns a JSON ObjectMapper that is configured as defined using ObjectMapperConfig and ModuleFactory.
        Specified by:
        getDefaultObjectMapper in interface com.anaptecs.jeaf.json.api.JSONTools
        Returns:
        ObjectMapper Object mapper that should be used for JSON serialization.
      • writeObject

        public void writeObject​(java.lang.Object pObject,
                                java.io.OutputStream pOutputStream)
                         throws com.anaptecs.jeaf.xfun.api.errorhandling.JEAFSystemException
        Method serializes the passed object to the passed stream.
        Specified by:
        writeObject in interface com.anaptecs.jeaf.json.api.JSONTools
        Parameters:
        pObject - Object that should be serialized as JSON. The parameter may be null.
        pOutputStream - Stream to which the object should be written. The parameter must not be null.
        Throws:
        com.anaptecs.jeaf.xfun.api.errorhandling.JEAFSystemException - if an error occurs during serialization
      • writeObject

        public void writeObject​(java.lang.Object pObject,
                                java.io.Writer pWriter)
                         throws com.anaptecs.jeaf.xfun.api.errorhandling.JEAFSystemException
        Method serializes the passed object to the passed writer.
        Specified by:
        writeObject in interface com.anaptecs.jeaf.json.api.JSONTools
        Parameters:
        pObject - Object that should be serialized as JSON. The parameter may be null.
        pWriter - Writer to which the object should be written. The parameter must not be null.
        Throws:
        com.anaptecs.jeaf.xfun.api.errorhandling.JEAFSystemException - if an error occurs during serialization
      • writeObject

        public void writeObject​(java.lang.Object pObject,
                                java.io.File pFile)
                         throws com.anaptecs.jeaf.xfun.api.errorhandling.JEAFSystemException
        Method serializes the passed object to the passed file.
        Specified by:
        writeObject in interface com.anaptecs.jeaf.json.api.JSONTools
        Parameters:
        pObject - Object that should be serialized as JSON. The parameter may be null.
        pFile - File to which the object should be written. The parameter must not be null.
        Throws:
        com.anaptecs.jeaf.xfun.api.errorhandling.JEAFSystemException - if an error occurs during serialization
      • writeObjectToString

        public java.lang.String writeObjectToString​(java.lang.Object pObject)
                                             throws com.anaptecs.jeaf.xfun.api.errorhandling.JEAFSystemException
        Method serializes the passed object as string.
        Specified by:
        writeObjectToString in interface com.anaptecs.jeaf.json.api.JSONTools
        Parameters:
        pObject - Object that should be serialized as JSON. The parameter may be null.
        Returns:
        String JSON serialized object as String. The method never returns null.
        Throws:
        com.anaptecs.jeaf.xfun.api.errorhandling.JEAFSystemException - if an error occurs during serialization
      • writeObjectToBytes

        public byte[] writeObjectToBytes​(java.lang.Object pObject)
                                  throws com.anaptecs.jeaf.xfun.api.errorhandling.JEAFSystemException
        Method serializes the passed object as byte array.
        Specified by:
        writeObjectToBytes in interface com.anaptecs.jeaf.json.api.JSONTools
        Parameters:
        pObject - Object that should be serialized as JSON. The parameter may be null.
        Returns:
        byte[] JSON serialized object as byte array. The method never returns null.
        Throws:
        com.anaptecs.jeaf.xfun.api.errorhandling.JEAFSystemException - if an error occurs during serialization
      • writeObjects

        public void writeObjects​(java.util.Collection<?> pObjects,
                                 java.io.OutputStream pOutputStream,
                                 java.lang.Class<?> pObjectType)
                          throws com.anaptecs.jeaf.xfun.api.errorhandling.JEAFSystemException
        Method serializes the passed Collection to the passed stream.
        Specified by:
        writeObjects in interface com.anaptecs.jeaf.json.api.JSONTools
        Parameters:
        pObjects - Collection of objects that should be serialized as JSON. The parameter may be null.
        pOutputStream - Stream to which the object should be written. The parameter must not be null.
        pObjectType - Class object representing the type of objects that are inside the collection. As type info of Java generics is not present at runtime this information has to be passed as additional parameter.
        Throws:
        com.anaptecs.jeaf.xfun.api.errorhandling.JEAFSystemException - if an error occurs during serialization
      • writeObjects

        public void writeObjects​(java.util.Collection<?> pObjects,
                                 java.io.Writer pWriter,
                                 java.lang.Class<?> pObjectType)
                          throws com.anaptecs.jeaf.xfun.api.errorhandling.JEAFSystemException
        Method serializes the passed Collection to the passed writer.
        Specified by:
        writeObjects in interface com.anaptecs.jeaf.json.api.JSONTools
        Parameters:
        pObjects - Collection of objects that should be serialized as JSON. The parameter may be null.
        pWriter - Writer to which the object should be written. The parameter must not be null.
        pObjectType - Class object representing the type of objects that are inside the collection. As type info of Java generics is not present at runtime this information has to be passed as additional parameter.
        Throws:
        com.anaptecs.jeaf.xfun.api.errorhandling.JEAFSystemException - if an error occurs during serialization
      • writeObjects

        public void writeObjects​(java.util.Collection<?> pObjects,
                                 java.io.File pFile,
                                 java.lang.Class<?> pObjectType)
                          throws com.anaptecs.jeaf.xfun.api.errorhandling.JEAFSystemException
        Method serializes the passed Collection to the passed file.
        Specified by:
        writeObjects in interface com.anaptecs.jeaf.json.api.JSONTools
        Parameters:
        pObjects - Collection of objects that should be serialized as JSON. The parameter may be null.
        pFile - File to which the object should be written. The parameter must not be null.
        pObjectType - Class object representing the type of objects that are inside the collection. As type info of Java generics is not present at runtime this information has to be passed as additional parameter.
        Throws:
        com.anaptecs.jeaf.xfun.api.errorhandling.JEAFSystemException - if an error occurs during serialization
      • writeObjectsToString

        public java.lang.String writeObjectsToString​(java.util.Collection<?> pObjects,
                                                     java.lang.Class<?> pObjectType)
                                              throws com.anaptecs.jeaf.xfun.api.errorhandling.JEAFSystemException
        Method serializes the passed Collection as string.
        Specified by:
        writeObjectsToString in interface com.anaptecs.jeaf.json.api.JSONTools
        Parameters:
        pObjects - Collection of objects that should be serialized as JSON. The parameter may be null.
        pObjectType - Class object representing the type of objects that are inside the collection. As type info of Java generics is not present at runtime this information has to be passed as additional parameter.
        Returns:
        String JSON serialized object as String. The method never returns null.
        Throws:
        com.anaptecs.jeaf.xfun.api.errorhandling.JEAFSystemException - if an error occurs during serialization
      • writeObjectsToBytes

        public byte[] writeObjectsToBytes​(java.util.Collection<?> pObjects,
                                          java.lang.Class<?> pObjectType)
                                   throws com.anaptecs.jeaf.xfun.api.errorhandling.JEAFSystemException
        Method serializes the passed Collection as byte array.
        Specified by:
        writeObjectsToBytes in interface com.anaptecs.jeaf.json.api.JSONTools
        Parameters:
        pObjects - Collection of objects that should be serialized as JSON. The parameter may be null.
        pObjectType - Class object representing the type of objects that are inside the collection. As type info of Java generics is not present at runtime this information has to be passed as additional parameter.
        Returns:
        String JSON serialized object as String. The method never returns null.
        Throws:
        com.anaptecs.jeaf.xfun.api.errorhandling.JEAFSystemException - if an error occurs during serialization
      • read

        public <T> T read​(java.io.InputStream pInputStream,
                          java.lang.Class<T> pResultType)
                   throws com.anaptecs.jeaf.xfun.api.errorhandling.JEAFSystemException
        Method deserializes the data of passed stream into an object of the passed type.
        Specified by:
        read in interface com.anaptecs.jeaf.json.api.JSONTools
        Parameters:
        pInputStream - Stream from which the data should be read. The parameter must not be null.
        pResultType - Type of the object that should be created. The parameter must not be null.
        Returns:
        T Object of passed type that was created. The method may return null if null was serialized.
        Throws:
        com.anaptecs.jeaf.xfun.api.errorhandling.JEAFSystemException - if an error occurs during deserialization
      • read

        public <T> T read​(java.io.Reader pReader,
                          java.lang.Class<T> pResultType)
                   throws com.anaptecs.jeaf.xfun.api.errorhandling.JEAFSystemException
        Method deserializes the data from the passed reader into an object of the passed type.
        Specified by:
        read in interface com.anaptecs.jeaf.json.api.JSONTools
        Parameters:
        pReader - Reader from which the data should be read. The parameter must not be null.
        pResultType - Type of the object that should be created. The parameter must not be null.
        Returns:
        T Object of passed type that was created. The method may return null if null was serialized.
        Throws:
        com.anaptecs.jeaf.xfun.api.errorhandling.JEAFSystemException - if an error occurs during deserialization
      • read

        public <T> T read​(java.io.File pFile,
                          java.lang.Class<T> pResultType)
                   throws com.anaptecs.jeaf.xfun.api.errorhandling.JEAFSystemException
        Method deserializes the data from the passed file into an object of the passed type.
        Specified by:
        read in interface com.anaptecs.jeaf.json.api.JSONTools
        Parameters:
        pFile - File from which the data should be read. The parameter must not be null.
        pResultType - Type of the object that should be created. The parameter must not be null.
        Returns:
        T Object of passed type that was created. The method may return null if null was serialized.
        Throws:
        com.anaptecs.jeaf.xfun.api.errorhandling.JEAFSystemException - if an error occurs during deserialization
      • read

        public <T> T read​(java.lang.String pString,
                          java.lang.Class<T> pResultType)
                   throws com.anaptecs.jeaf.xfun.api.errorhandling.JEAFSystemException
        Method deserializes the passed string into an object of the passed type.
        Specified by:
        read in interface com.anaptecs.jeaf.json.api.JSONTools
        Parameters:
        pString - String from which the data should be read. The parameter must not be null.
        pResultType - Type of the object that should be created. The parameter must not be null.
        Returns:
        T Object of passed type that was created. The method may return null if null was serialized.
        Throws:
        com.anaptecs.jeaf.xfun.api.errorhandling.JEAFSystemException - if an error occurs during deserialization
      • read

        public <T> T read​(byte[] pBytes,
                          java.lang.Class<T> pResultType)
                   throws com.anaptecs.jeaf.xfun.api.errorhandling.JEAFSystemException
        Method deserializes the passed byte array into an object of the passed type.
        Specified by:
        read in interface com.anaptecs.jeaf.json.api.JSONTools
        Parameters:
        pBytes - Byte array from which the data should be read. The parameter must not be null.
        pResultType - Type of the object that should be created. The parameter must not be null.
        Returns:
        T Object of passed type that was created. The method may return null if null was serialized.
        Throws:
        com.anaptecs.jeaf.xfun.api.errorhandling.JEAFSystemException - if an error occurs during deserialization
      • read

        public <T> T read​(java.lang.String pString,
                          com.anaptecs.jeaf.json.api.ObjectType pResultType)
                   throws com.anaptecs.jeaf.xfun.api.errorhandling.JEAFSystemException
        Method deserializes the passed string into an object of the passed type.
        Specified by:
        read in interface com.anaptecs.jeaf.json.api.JSONTools
        Parameters:
        pString - String from which the data should be read. The parameter must not be null.
        pResultType - Type of the object that should be created. The parameter must not be null.
        Returns:
        T Object of passed type that was created. The method may return null if null was serialized.
        Throws:
        com.anaptecs.jeaf.xfun.api.errorhandling.JEAFSystemException - if an error occurs during deserialization
      • read

        public <T> T read​(byte[] pBytes,
                          com.anaptecs.jeaf.json.api.ObjectType pResultType)
                   throws com.anaptecs.jeaf.xfun.api.errorhandling.JEAFSystemException
        Method deserializes the passed byte array into an object of the passed type.
        Specified by:
        read in interface com.anaptecs.jeaf.json.api.JSONTools
        Parameters:
        pBytes - Byte array from which the data should be read. The parameter must not be null.
        pResultType - Type of the object that should be created. The parameter must not be null.
        Returns:
        T Object of passed type that was created. The method may return null if null was serialized.
        Throws:
        com.anaptecs.jeaf.xfun.api.errorhandling.JEAFSystemException - if an error occurs during deserialization
      • read

        public <T> T read​(java.io.InputStream pInputStream,
                          com.anaptecs.jeaf.json.api.ObjectType pResultType)
                   throws com.anaptecs.jeaf.xfun.api.errorhandling.JEAFSystemException
        Method deserializes the data of passed stream into an object of the passed type.
        Specified by:
        read in interface com.anaptecs.jeaf.json.api.JSONTools
        Parameters:
        pInputStream - Stream from which the data should be read. The parameter must not be null.
        pResultType - Type of the object that should be created. The parameter must not be null.
        Returns:
        T Object of passed type that was created. The method may return null if null was serialized.
        Throws:
        com.anaptecs.jeaf.xfun.api.errorhandling.JEAFSystemException - if an error occurs during deserialization
      • read

        public <T> T read​(java.io.Reader pReader,
                          com.anaptecs.jeaf.json.api.ObjectType pResultType)
                   throws com.anaptecs.jeaf.xfun.api.errorhandling.JEAFSystemException
        Method deserializes the data from the passed reader into an object of the passed type.
        Specified by:
        read in interface com.anaptecs.jeaf.json.api.JSONTools
        Parameters:
        pReader - Reader from which the data should be read. The parameter must not be null.
        pResultType - Type of the object that should be created. The parameter must not be null.
        Returns:
        T Object of passed type that was created. The method may return null if null was serialized.
        Throws:
        com.anaptecs.jeaf.xfun.api.errorhandling.JEAFSystemException - if an error occurs during deserialization
      • read

        public <T> T read​(java.io.File pFile,
                          com.anaptecs.jeaf.json.api.ObjectType pResultType)
                   throws com.anaptecs.jeaf.xfun.api.errorhandling.JEAFSystemException
        Method deserializes the data from the passed file into an object of the passed type.
        Specified by:
        read in interface com.anaptecs.jeaf.json.api.JSONTools
        Parameters:
        pFile - File from which the data should be read. The parameter must not be null.
        pResultType - Type of the object that should be created. The parameter must not be null.
        Returns:
        T Object of passed type that was created. The method may return null if null was serialized.
        Throws:
        com.anaptecs.jeaf.xfun.api.errorhandling.JEAFSystemException - if an error occurs during deserialization
      • readToCollection

        public <T> T readToCollection​(java.io.InputStream pInputStream,
                                      java.lang.Class<? extends java.util.Collection> pCollectionType,
                                      java.lang.Class<?> pResultType)
                               throws com.anaptecs.jeaf.xfun.api.errorhandling.JEAFSystemException
        Method deserializes the data of passed stream into a List of objects of the passed type.
        Specified by:
        readToCollection in interface com.anaptecs.jeaf.json.api.JSONTools
        Parameters:
        pInputStream - Stream from which the data should be read. The parameter must not be null.
        pResultType - Type of the object that should be created. The parameter must not be null.
        Returns:
        List List of objects of passed type that was created from the JSON data. The method may return null if null was serialized.
        Throws:
        com.anaptecs.jeaf.xfun.api.errorhandling.JEAFSystemException - if an error occurs during deserialization
      • readToCollection

        public <T> T readToCollection​(java.io.Reader pReader,
                                      java.lang.Class<? extends java.util.Collection> pCollectionType,
                                      java.lang.Class<?> pResultType)
                               throws com.anaptecs.jeaf.xfun.api.errorhandling.JEAFSystemException
        Method deserializes the data from the passed reader into a List of objects of the passed type.
        Specified by:
        readToCollection in interface com.anaptecs.jeaf.json.api.JSONTools
        Parameters:
        pReader - Reader from which the data should be read. The parameter must not be null.
        pResultType - Type of the object that should be created. The parameter must not be null.
        Returns:
        List List of objects of passed type that was created from the JSON data. The method may return null if null was serialized.
        Throws:
        com.anaptecs.jeaf.xfun.api.errorhandling.JEAFSystemException - if an error occurs during deserialization
      • readToCollection

        public <T> T readToCollection​(java.io.File pFile,
                                      java.lang.Class<? extends java.util.Collection> pCollectionType,
                                      java.lang.Class<?> pResultType)
                               throws com.anaptecs.jeaf.xfun.api.errorhandling.JEAFSystemException
        Method deserializes the data from the passed file into a List of objects of the passed type.
        Specified by:
        readToCollection in interface com.anaptecs.jeaf.json.api.JSONTools
        Parameters:
        pFile - File from which the data should be read. The parameter must not be null.
        pResultType - Type of the object that should be created. The parameter must not be null.
        Returns:
        List List of objects of passed type that was created from the JSON data. The method may return null if null was serialized.
        Throws:
        com.anaptecs.jeaf.xfun.api.errorhandling.JEAFSystemException - if an error occurs during deserialization
      • readToCollection

        public <T> T readToCollection​(java.lang.String pString,
                                      java.lang.Class<? extends java.util.Collection> pCollectionType,
                                      java.lang.Class<?> pResultType)
                               throws com.anaptecs.jeaf.xfun.api.errorhandling.JEAFSystemException
        Method deserializes the passed string into a List of objects of the passed type.
        Specified by:
        readToCollection in interface com.anaptecs.jeaf.json.api.JSONTools
        Parameters:
        pString - String from which the data should be read. The parameter must not be null.
        pResultType - Type of the object that should be created. The parameter must not be null.
        Returns:
        List List of objects of passed type that was created from the JSON data. The method may return null if null was serialized.
        Throws:
        com.anaptecs.jeaf.xfun.api.errorhandling.JEAFSystemException - if an error occurs during deserialization
      • readToCollection

        public <T> T readToCollection​(byte[] pBytes,
                                      java.lang.Class<? extends java.util.Collection> pCollectionType,
                                      java.lang.Class<?> pResultType)
                               throws com.anaptecs.jeaf.xfun.api.errorhandling.JEAFSystemException
        Method deserializes the passed string into a List of objects of the passed type.
        Specified by:
        readToCollection in interface com.anaptecs.jeaf.json.api.JSONTools
        Parameters:
        pBytes - Byte array from which the data should be read. The parameter must not be null.
        pResultType - Type of the object that should be created. The parameter must not be null.
        Returns:
        List List of objects of passed type that was created from the JSON data. The method may return null if null was serialized.
        Throws:
        com.anaptecs.jeaf.xfun.api.errorhandling.JEAFSystemException - if an error occurs during deserialization