Package yapion.parser

Class YAPIONParser


  • public final class YAPIONParser
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      YAPIONParser​(@lombok.NonNull byte[] bytes)
      Creates a YAPIONParser for parsing a byte array to an YAPIONObject.
      YAPIONParser​(@lombok.NonNull char[] chars)
      Creates a YAPIONParser for parsing a char array to an YAPIONObject.
      YAPIONParser​(@NonNull java.io.InputStream inputStream)
      Creates a YAPIONParser for parsing an InputStream to an YAPIONObject.
      YAPIONParser​(@NonNull java.io.InputStream inputStream, boolean stopOnStreamEnd)
      Creates a YAPIONParser for parsing an InputStream to an YAPIONObject.
      YAPIONParser​(@NonNull java.lang.String string)
      Creates a YAPIONParser for parsing a string to an YAPIONObject.
      YAPIONParser​(@NonNull java.lang.StringBuilder stringBuilder)
      Creates a YAPIONParser for parsing a StringBuilder to an YAPIONObject.
    • Method Summary

      Modifier and Type Method Description
      static YAPIONObject mapJSON​(java.lang.String s)
      This method first parses the String to a YAPIONObject with parseJSON(String) and maps the YAPIONObject back.
      static YAPIONObject mapJSON​(YAPIONObject yapionObject)
      This method maps every corrupted YAPIONPointer and YAPIONMap back to their corresponding YAPION representations.
      YAPIONParser parse()
      Parses the InputStream or String to an YAPIONObject.
      static YAPIONObject parse​(java.io.InputStream inputStream)
      Parses the InputStream to an YAPIONObject.
      static YAPIONObject parse​(java.lang.String s)
      Parses the String to an YAPIONObject.
      static YAPIONObject parseJSON​(java.lang.String s)
      Parses the JSON String to an YAPIONObject.
      static YAPIONObject parseOld​(java.io.InputStream inputStream)
      Deprecated.
      since 0.23.0
      static YAPIONObject parseOld​(java.lang.String s)
      Deprecated.
      since 0.23.0
      YAPIONObject result()
      Returns the YAPIONObject parsed by parse()
      YAPIONParser setReferenceFunction​(@NonNull ReferenceFunction referenceFunction)  
      • Methods inherited from class java.lang.Object

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

      • YAPIONParser

        public YAPIONParser​(@NonNull
                            @NonNull java.lang.String string)
        Creates a YAPIONParser for parsing a string to an YAPIONObject.
        Parameters:
        string - to parse from
      • YAPIONParser

        public YAPIONParser​(@NonNull
                            @NonNull java.lang.StringBuilder stringBuilder)
        Creates a YAPIONParser for parsing a StringBuilder to an YAPIONObject.
        Parameters:
        stringBuilder - to parse from
      • YAPIONParser

        public YAPIONParser​(@NonNull
                            @lombok.NonNull byte[] bytes)
        Creates a YAPIONParser for parsing a byte array to an YAPIONObject.
        Parameters:
        bytes - to parse from
      • YAPIONParser

        public YAPIONParser​(@NonNull
                            @lombok.NonNull char[] chars)
        Creates a YAPIONParser for parsing a char array to an YAPIONObject.
        Parameters:
        chars - to parse from
      • YAPIONParser

        public YAPIONParser​(@NonNull
                            @NonNull java.io.InputStream inputStream)
        Creates a YAPIONParser for parsing an InputStream to an YAPIONObject.
        Parameters:
        inputStream - to parse from
      • YAPIONParser

        public YAPIONParser​(@NonNull
                            @NonNull java.io.InputStream inputStream,
                            boolean stopOnStreamEnd)
        Creates a YAPIONParser for parsing an InputStream to an YAPIONObject.
        Parameters:
        inputStream - to parse from
        stopOnStreamEnd - true if it should stop at the end of the stream, false otherwise
    • Method Detail

      • parse

        public static YAPIONObject parse​(java.lang.String s)
        Parses the String to an YAPIONObject.
        Parameters:
        s - the string to parse
        Returns:
        YAPIONObject parsed out of the string
      • parseOld

        @Deprecated
        public static YAPIONObject parseOld​(java.lang.String s)
        Deprecated.
        since 0.23.0
        Parses the String to an YAPIONObject.
        Parameters:
        s - the string to parse
        Returns:
        YAPIONObject parsed out of the string
      • parseJSON

        public static YAPIONObject parseJSON​(java.lang.String s)
        Parses the JSON String to an YAPIONObject.
        Parameters:
        s - the string to parse
        Returns:
        YAPIONObject parsed out of the string
      • mapJSON

        public static YAPIONObject mapJSON​(YAPIONObject yapionObject)
        This method maps every corrupted YAPIONPointer and YAPIONMap back to their corresponding YAPION representations. Useful to serialize a java object with JSON and create the underlying Java object back out of this JSON representation.

        {"@pointer":"0000000000000000"} will be interpreted as a pointer.
        {"@mapping":[]} will be interpreted as a map.

        Some specialties for non Lossy JSON ObjectOutput.toJSON(AbstractOutput) instead of ObjectOutput.toJSONLossy(AbstractOutput) will be the primitive types that are represented by an YAPIONObject instead. This is to ensure that Data loss will not happen.
        {"@byte":0} will be interpreted as a Byte
        {"@short":0} will be interpreted as a Short
        {"@int":0} will be interpreted as an Integer
        {"@long":0} will be interpreted as a Long
        {"@bint":"0"} will be interpreted as a BigInteger
        {"@char":""} will be interpreted as a Character
        {"@float":0.0} will be interpreted as a Float
        {"@double":0.0} will be interpreted as a Double
        {"@bdecimal":"0.0"} will be interpreted as a BigDecimal

        You can find more information in the classes YAPIONMap, YAPIONPointer and YAPIONValue. These classes have the method ObjectOutput.toJSON(AbstractOutput) and ObjectOutput.toJSONLossy(AbstractOutput) overridden with a specific implementation for these types. The difference between those methods should be the YAPIONValue implementation as it tries to not lose any data with YAPIONValue.toJSON(AbstractOutput) and will discard some data by using YAPIONValue.toJSONLossy(AbstractOutput). The data that gets lost are the type of numbers, floating point numbers and the information whether or not the String was previously a Character.
        Parameters:
        yapionObject - the YAPIONObject to map
        Returns:
        YAPIONObject with mapped YAPIONPointer and YAPIONMap
      • mapJSON

        public static YAPIONObject mapJSON​(java.lang.String s)
        This method first parses the String to a YAPIONObject with parseJSON(String) and maps the YAPIONObject back. After parsing this method maps every corrupted YAPIONPointer and YAPIONMap back to their corresponding YAPION representations. Useful to serialize a java object with JSON and create the underlying Java object back out of this JSON representation.

        {"@pointer":"0000000000000000"} will be interpreted as a pointer.
        {"@mapping":[]} will be interpreted as a map.

        Some specialties for non Lossy JSON ObjectOutput.toJSON(AbstractOutput) instead of ObjectOutput.toJSONLossy(AbstractOutput) will be the primitive types that are represented by an YAPIONObject instead. This is to ensure that Data loss will not happen.
        {"@byte":0} will be interpreted as a Byte
        {"@short":0} will be interpreted as a Short
        {"@int":0} will be interpreted as an Integer
        {"@long":0} will be interpreted as a Long
        {"@bint":0} will be interpreted as a BigInteger
        {"@char":""} will be interpreted as a Character
        {"@float":0.0} will be interpreted as a Float
        {"@double":0.0} will be interpreted as a Double
        {"@bdecimal":0.0} will be interpreted as a BigDecimal

        You can find more information in the classes YAPIONMap, YAPIONPointer and YAPIONValue. These classes have the method ObjectOutput.toJSON(AbstractOutput) and ObjectOutput.toJSONLossy(AbstractOutput) overridden with a specific implementation for these types. The difference between those methods should be the YAPIONValue implementation as it tries to not lose any data with YAPIONValue.toJSON(AbstractOutput) and will discard some data by using YAPIONValue.toJSONLossy(AbstractOutput). The data that gets lost are the type of numbers, floating point numbers and the information whether or not the String was previously a Character.
        Parameters:
        s - the String to map
        Returns:
        YAPIONObject with mapped YAPIONPointer and YAPIONMap
      • parse

        public static YAPIONObject parse​(java.io.InputStream inputStream)
        Parses the InputStream to an YAPIONObject. This method only parses the next YAPIONObject and tries to read until the YAPIONObject is finished. It will not cancel even when the end of Stream is reached. It will only cancel after it has a complete and valid YAPIONObject or 1 second without any new Input passed.
        Parameters:
        inputStream - the inputStream to parse
        Returns:
        YAPIONObject parsed out of the string
      • parseOld

        @Deprecated
        public static YAPIONObject parseOld​(java.io.InputStream inputStream)
        Deprecated.
        since 0.23.0
        Parses the InputStream to an YAPIONObject. This method only parses the next YAPIONObject and tries to read until the YAPIONObject is finished. It will not cancel even when the end of Stream is reached. It will only cancel after it has a complete and valid YAPIONObject or 1 second without any new Input passed.
        Parameters:
        inputStream - the inputStream to parse
        Returns:
        YAPIONObject parsed out of the string
      • parse

        public YAPIONParser parse()
        Parses the InputStream or String to an YAPIONObject. If an InputStream is present this method only parses the next YAPIONObject and tries to read until the YAPIONObject is finished. It will not cancel even when the end of Steam is reached. It will only cancel after it has a complete and valid YAPIONObject.
      • result

        public YAPIONObject result()
        Returns the YAPIONObject parsed by parse()
        Returns:
        the YAPIONObject