Class JsonTraverser


  • public class JsonTraverser
    extends Traverser
    The JsonTraverser converts a preparsed JsonValue object to a corresponding Java object. todo: introduce boolean in traverser that checks if read a json object in map is ok
    • Nested Class Summary

    • Constructor Summary

      Constructors 
      Constructor Description
      JsonTraverser()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Class<?> findClazz​(java.lang.Object object, java.lang.ClassLoader targetcl)
      Find the class of an object.
      static java.lang.Class<?> findClazzOfJsonObject​(com.eclipsesource.json.JsonObject object, java.lang.ClassLoader targetcl)
      Find the class of an object.
      static java.util.List<ITraverseProcessor> getDefaultReadProcessorsCopy()
      Get a copy of the default read processors.
      static java.util.List<ITraverseProcessor> getDefaultWriteProcessorsCopy()
      Get a copy of the default read processors.
      protected static JsonTraverser getReadTraverser()  
      protected static Traverser getWriteTraverser()  
      static java.lang.Object objectFromByteArray​(byte[] val, java.lang.ClassLoader classloader)
      Convert a byte array (of an xml) to an object.
      static java.lang.Object objectFromByteArray​(byte[] val, java.lang.ClassLoader classloader, IErrorReporter rep)
      Convert a byte array (of an xml) to an object.
      static <T> T objectFromByteArray​(byte[] val, java.lang.ClassLoader classloader, IErrorReporter rep, java.lang.String enc, java.lang.Class<T> clazz)
      Convert a byte array (of an xml) to an object.
      static <T> T objectFromByteArray​(byte[] val, java.lang.ClassLoader classloader, IErrorReporter rep, java.lang.String enc, java.lang.Class<T> clazz, java.util.List<ITraverseProcessor> procs, java.util.List<ITraverseProcessor> postprocs)
      Convert a byte array (of an xml) to an object.
      static <T> T objectFromByteArray​(byte[] val, java.lang.ClassLoader classloader, IErrorReporter rep, java.lang.String enc, java.lang.Class<T> clazz, java.util.List<ITraverseProcessor> procs, java.util.List<ITraverseProcessor> postprocs, java.lang.Object usercontext)
      Convert a byte array (of an xml) to an object.
      static java.lang.Object objectFromByteArray​(byte[] val, java.lang.ClassLoader classloader, java.lang.String enc)
      Convert a byte array (of an xml) to an object.
      static <T> T objectFromString​(java.lang.String val, java.lang.ClassLoader classloader, IErrorReporter rep, java.lang.Class<T> clazz)
      Convert a byte array (of an xml) to an object.
      static <T> T objectFromString​(java.lang.String val, java.lang.ClassLoader classloader, IErrorReporter rep, java.lang.Class<T> clazz, java.util.List<ITraverseProcessor> processors)
      Convert a byte array (of an xml) to an object.
      static <T> T objectFromString​(java.lang.String val, java.lang.ClassLoader classloader, IErrorReporter rep, java.lang.Class<T> clazz, java.util.List<ITraverseProcessor> processors, java.util.List<ITraverseProcessor> postprocessors)
      Convert a byte array (of an xml) to an object.
      static <T> T objectFromString​(java.lang.String val, java.lang.ClassLoader classloader, IErrorReporter rep, java.lang.Class<T> clazz, java.util.List<ITraverseProcessor> processors, java.util.List<ITraverseProcessor> postprocessors, java.lang.Object usercontext)
      Convert a byte array (of an xml) to an object.
      static <T> T objectFromString​(java.lang.String val, java.lang.ClassLoader classloader, java.lang.Class<T> clazz)
      Convert a byte array (of an xml) to an object.
      static byte[] objectToByteArray​(java.lang.Object val, java.lang.ClassLoader classloader)
      Convert to a byte array.
      static byte[] objectToByteArray​(java.lang.Object val, java.lang.ClassLoader classloader, java.lang.String enc)
      Convert to a byte array.
      static byte[] objectToByteArray​(java.lang.Object val, java.lang.ClassLoader classloader, java.lang.String enc, boolean writeclass)
      Convert to a byte array.
      static byte[] objectToByteArray​(java.lang.Object val, java.lang.ClassLoader classloader, java.lang.String enc, boolean writeclass, boolean writeid, java.util.Map<java.lang.Class<?>,​java.util.Set<java.lang.String>> excludes, java.util.List<ITraverseProcessor> conversionprocessors, java.util.List<ITraverseProcessor> processors)
      Convert to a byte array.
      static byte[] objectToByteArray​(java.lang.Object val, java.lang.ClassLoader classloader, java.lang.String enc, boolean writeclass, boolean writeid, java.util.Map<java.lang.Class<?>,​java.util.Set<java.lang.String>> excludes, java.util.List<ITraverseProcessor> conversionprocessors, java.util.List<ITraverseProcessor> processors, java.lang.Object usercontext)
      Convert to a byte array.
      static byte[] objectToByteArray​(java.lang.Object val, java.lang.ClassLoader classloader, java.lang.String enc, boolean writeclass, java.util.Map<java.lang.Class<?>,​java.util.Set<java.lang.String>> excludes)
      Convert to a byte array.
      static byte[] objectToByteArray​(java.lang.Object val, java.lang.ClassLoader classloader, java.lang.String enc, boolean writeclass, java.util.Map<java.lang.Class<?>,​java.util.Set<java.lang.String>> excludes, java.util.List<ITraverseProcessor> processors)
      Convert to a byte array.
      static java.lang.String objectToString​(java.lang.Object val, java.lang.ClassLoader classloader)
      Convert to a string.
      static java.lang.String objectToString​(java.lang.Object val, java.lang.ClassLoader classloader, boolean writeclass)
      Convert to a string.
      static java.lang.String objectToString​(java.lang.Object val, java.lang.ClassLoader classloader, boolean writeclass, boolean writeid, java.util.Map<java.lang.Class<?>,​java.util.Set<java.lang.String>> excludes, java.util.List<ITraverseProcessor> preprocessors, java.util.List<ITraverseProcessor> processors)
      Convert to a string.
      static java.lang.String objectToString​(java.lang.Object val, java.lang.ClassLoader classloader, boolean writeclass, boolean writeid, java.util.Map<java.lang.Class<?>,​java.util.Set<java.lang.String>> excludes, java.util.List<ITraverseProcessor> preprocessors, java.util.List<ITraverseProcessor> processors, java.lang.Object usercontext)
      Convert to a string.
      static java.lang.String objectToString​(java.lang.Object val, java.lang.ClassLoader classloader, boolean writeclass, java.util.Map<java.lang.Class<?>,​java.util.Set<java.lang.String>> excludes)
      Convert to a string.
      static java.lang.String objectToString​(java.lang.Object val, java.lang.ClassLoader classloader, boolean writeclass, java.util.Map<java.lang.Class<?>,​java.util.Set<java.lang.String>> excludes, java.util.List<ITraverseProcessor> processors)
      Convert to a string.
      static java.lang.String objectToString​(java.lang.Object val, java.lang.ClassLoader classloader, boolean writeclass, java.util.Map<java.lang.Class<?>,​java.util.Set<java.lang.String>> excludes, java.util.List<ITraverseProcessor> preprocessors, java.util.List<ITraverseProcessor> processors)
      Convert to a string.
      static java.lang.String prettifyJson​(java.lang.String json)
      Prettifies a JSON source.
      • Methods inherited from class java.lang.Object

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

      • JsonTraverser

        public JsonTraverser()
    • Method Detail

      • findClazz

        public java.lang.Class<?> findClazz​(java.lang.Object object,
                                            java.lang.ClassLoader targetcl)
        Find the class of an object.
        Overrides:
        findClazz in class Traverser
        Parameters:
        object - The object.
        targetcl - The classloader.
        Returns:
        The objects class.
      • findClazzOfJsonObject

        public static java.lang.Class<?> findClazzOfJsonObject​(com.eclipsesource.json.JsonObject object,
                                                               java.lang.ClassLoader targetcl)
        Find the class of an object.
        Parameters:
        object - The object.
        Returns:
        The objects class.
      • getWriteTraverser

        protected static Traverser getWriteTraverser()
        Returns:
      • getReadTraverser

        protected static JsonTraverser getReadTraverser()
        Returns:
      • objectToByteArray

        public static byte[] objectToByteArray​(java.lang.Object val,
                                               java.lang.ClassLoader classloader)
        Convert to a byte array.
      • objectToByteArray

        public static byte[] objectToByteArray​(java.lang.Object val,
                                               java.lang.ClassLoader classloader,
                                               java.lang.String enc)
        Convert to a byte array.
      • objectToByteArray

        public static byte[] objectToByteArray​(java.lang.Object val,
                                               java.lang.ClassLoader classloader,
                                               java.lang.String enc,
                                               boolean writeclass)
        Convert to a byte array.
      • objectToByteArray

        public static byte[] objectToByteArray​(java.lang.Object val,
                                               java.lang.ClassLoader classloader,
                                               java.lang.String enc,
                                               boolean writeclass,
                                               java.util.Map<java.lang.Class<?>,​java.util.Set<java.lang.String>> excludes)
        Convert to a byte array.
      • objectToByteArray

        public static byte[] objectToByteArray​(java.lang.Object val,
                                               java.lang.ClassLoader classloader,
                                               java.lang.String enc,
                                               boolean writeclass,
                                               java.util.Map<java.lang.Class<?>,​java.util.Set<java.lang.String>> excludes,
                                               java.util.List<ITraverseProcessor> processors)
        Convert to a byte array.
      • objectToByteArray

        public static byte[] objectToByteArray​(java.lang.Object val,
                                               java.lang.ClassLoader classloader,
                                               java.lang.String enc,
                                               boolean writeclass,
                                               boolean writeid,
                                               java.util.Map<java.lang.Class<?>,​java.util.Set<java.lang.String>> excludes,
                                               java.util.List<ITraverseProcessor> conversionprocessors,
                                               java.util.List<ITraverseProcessor> processors)
        Convert to a byte array.
      • objectToByteArray

        public static byte[] objectToByteArray​(java.lang.Object val,
                                               java.lang.ClassLoader classloader,
                                               java.lang.String enc,
                                               boolean writeclass,
                                               boolean writeid,
                                               java.util.Map<java.lang.Class<?>,​java.util.Set<java.lang.String>> excludes,
                                               java.util.List<ITraverseProcessor> conversionprocessors,
                                               java.util.List<ITraverseProcessor> processors,
                                               java.lang.Object usercontext)
        Convert to a byte array.
      • objectToString

        public static java.lang.String objectToString​(java.lang.Object val,
                                                      java.lang.ClassLoader classloader)
        Convert to a string.
      • objectToString

        public static java.lang.String objectToString​(java.lang.Object val,
                                                      java.lang.ClassLoader classloader,
                                                      boolean writeclass)
        Convert to a string.
      • objectToString

        public static java.lang.String objectToString​(java.lang.Object val,
                                                      java.lang.ClassLoader classloader,
                                                      boolean writeclass,
                                                      java.util.Map<java.lang.Class<?>,​java.util.Set<java.lang.String>> excludes)
        Convert to a string.
      • objectToString

        public static java.lang.String objectToString​(java.lang.Object val,
                                                      java.lang.ClassLoader classloader,
                                                      boolean writeclass,
                                                      java.util.Map<java.lang.Class<?>,​java.util.Set<java.lang.String>> excludes,
                                                      java.util.List<ITraverseProcessor> processors)
        Convert to a string.
      • objectToString

        public static java.lang.String objectToString​(java.lang.Object val,
                                                      java.lang.ClassLoader classloader,
                                                      boolean writeclass,
                                                      java.util.Map<java.lang.Class<?>,​java.util.Set<java.lang.String>> excludes,
                                                      java.util.List<ITraverseProcessor> preprocessors,
                                                      java.util.List<ITraverseProcessor> processors)
        Convert to a string.
      • objectToString

        public static java.lang.String objectToString​(java.lang.Object val,
                                                      java.lang.ClassLoader classloader,
                                                      boolean writeclass,
                                                      boolean writeid,
                                                      java.util.Map<java.lang.Class<?>,​java.util.Set<java.lang.String>> excludes,
                                                      java.util.List<ITraverseProcessor> preprocessors,
                                                      java.util.List<ITraverseProcessor> processors)
        Convert to a string.
      • objectToString

        public static java.lang.String objectToString​(java.lang.Object val,
                                                      java.lang.ClassLoader classloader,
                                                      boolean writeclass,
                                                      boolean writeid,
                                                      java.util.Map<java.lang.Class<?>,​java.util.Set<java.lang.String>> excludes,
                                                      java.util.List<ITraverseProcessor> preprocessors,
                                                      java.util.List<ITraverseProcessor> processors,
                                                      java.lang.Object usercontext)
        Convert to a string.
      • objectFromByteArray

        public static java.lang.Object objectFromByteArray​(byte[] val,
                                                           java.lang.ClassLoader classloader)
        Convert a byte array (of an xml) to an object.
        Parameters:
        val - The byte array.
        classloader - The class loader.
        Returns:
        The decoded object.
      • objectFromByteArray

        public static java.lang.Object objectFromByteArray​(byte[] val,
                                                           java.lang.ClassLoader classloader,
                                                           java.lang.String enc)
        Convert a byte array (of an xml) to an object.
        Parameters:
        val - The byte array.
        classloader - The class loader.
        Returns:
        The decoded object.
      • objectFromByteArray

        public static java.lang.Object objectFromByteArray​(byte[] val,
                                                           java.lang.ClassLoader classloader,
                                                           IErrorReporter rep)
        Convert a byte array (of an xml) to an object.
        Parameters:
        val - The byte array.
        classloader - The class loader.
        Returns:
        The decoded object.
      • objectFromByteArray

        public static <T> T objectFromByteArray​(byte[] val,
                                                java.lang.ClassLoader classloader,
                                                IErrorReporter rep,
                                                java.lang.String enc,
                                                java.lang.Class<T> clazz)
        Convert a byte array (of an xml) to an object.
        Parameters:
        val - The byte array.
        classloader - The class loader.
        Returns:
        The decoded object.
      • objectFromByteArray

        public static <T> T objectFromByteArray​(byte[] val,
                                                java.lang.ClassLoader classloader,
                                                IErrorReporter rep,
                                                java.lang.String enc,
                                                java.lang.Class<T> clazz,
                                                java.util.List<ITraverseProcessor> procs,
                                                java.util.List<ITraverseProcessor> postprocs)
        Convert a byte array (of an xml) to an object.
        Parameters:
        val - The byte array.
        classloader - The class loader.
        Returns:
        The decoded object.
      • objectFromByteArray

        public static <T> T objectFromByteArray​(byte[] val,
                                                java.lang.ClassLoader classloader,
                                                IErrorReporter rep,
                                                java.lang.String enc,
                                                java.lang.Class<T> clazz,
                                                java.util.List<ITraverseProcessor> procs,
                                                java.util.List<ITraverseProcessor> postprocs,
                                                java.lang.Object usercontext)
        Convert a byte array (of an xml) to an object.
        Parameters:
        val - The byte array.
        classloader - The class loader.
        Returns:
        The decoded object.
      • objectFromString

        public static <T> T objectFromString​(java.lang.String val,
                                             java.lang.ClassLoader classloader,
                                             java.lang.Class<T> clazz)
        Convert a byte array (of an xml) to an object.
        Parameters:
        val - The byte array.
        classloader - The class loader.
        Returns:
        The decoded object.
      • objectFromString

        public static <T> T objectFromString​(java.lang.String val,
                                             java.lang.ClassLoader classloader,
                                             IErrorReporter rep,
                                             java.lang.Class<T> clazz)
        Convert a byte array (of an xml) to an object.
        Parameters:
        val - The byte array.
        classloader - The class loader.
        Returns:
        The decoded object.
      • objectFromString

        public static <T> T objectFromString​(java.lang.String val,
                                             java.lang.ClassLoader classloader,
                                             IErrorReporter rep,
                                             java.lang.Class<T> clazz,
                                             java.util.List<ITraverseProcessor> processors)
        Convert a byte array (of an xml) to an object.
        Parameters:
        val - The byte array.
        classloader - The class loader.
        Returns:
        The decoded object.
      • objectFromString

        public static <T> T objectFromString​(java.lang.String val,
                                             java.lang.ClassLoader classloader,
                                             IErrorReporter rep,
                                             java.lang.Class<T> clazz,
                                             java.util.List<ITraverseProcessor> processors,
                                             java.util.List<ITraverseProcessor> postprocessors)
        Convert a byte array (of an xml) to an object.
        Parameters:
        val - The byte array.
        classloader - The class loader.
        Returns:
        The decoded object.
      • objectFromString

        public static <T> T objectFromString​(java.lang.String val,
                                             java.lang.ClassLoader classloader,
                                             IErrorReporter rep,
                                             java.lang.Class<T> clazz,
                                             java.util.List<ITraverseProcessor> processors,
                                             java.util.List<ITraverseProcessor> postprocessors,
                                             java.lang.Object usercontext)
        Convert a byte array (of an xml) to an object.
        Parameters:
        val - The byte array.
        classloader - The class loader.
        Returns:
        The decoded object.
      • prettifyJson

        public static java.lang.String prettifyJson​(java.lang.String json)
        Prettifies a JSON source.
        Parameters:
        json - The JSON.
        Returns:
        Prettified JSON or the original JSON on error.
      • getDefaultReadProcessorsCopy

        public static java.util.List<ITraverseProcessor> getDefaultReadProcessorsCopy()
        Get a copy of the default read processors.
        Returns:
        A copy of the read processor list.
      • getDefaultWriteProcessorsCopy

        public static java.util.List<ITraverseProcessor> getDefaultWriteProcessorsCopy()
        Get a copy of the default read processors.
        Returns:
        A copy of the read processor list.