Package yapion.parser
Class YAPIONParser
- java.lang.Object
-
- yapion.parser.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 withparseJSON(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.0static YAPIONObject
parseOld(java.lang.String s)
Deprecated.since 0.23.0YAPIONObject
result()
Returns the YAPIONObject parsed byparse()
YAPIONParser
setReferenceFunction(@NonNull ReferenceFunction referenceFunction)
-
-
-
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 fromstopOnStreamEnd
-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.0Parses 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 JSONObjectOutput.toJSON(AbstractOutput)
instead ofObjectOutput.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 aByte
{"@short":0} will be interpreted as aShort
{"@int":0} will be interpreted as anInteger
{"@long":0} will be interpreted as aLong
{"@bint":"0"} will be interpreted as aBigInteger
{"@char":""} will be interpreted as aCharacter
{"@float":0.0} will be interpreted as aFloat
{"@double":0.0} will be interpreted as aDouble
{"@bdecimal":"0.0"} will be interpreted as aBigDecimal
You can find more information in the classesYAPIONMap
,YAPIONPointer
andYAPIONValue
. These classes have the methodObjectOutput.toJSON(AbstractOutput)
andObjectOutput.toJSONLossy(AbstractOutput)
overridden with a specific implementation for these types. The difference between those methods should be theYAPIONValue
implementation as it tries to not lose any data withYAPIONValue.toJSON(AbstractOutput)
and will discard some data by usingYAPIONValue.toJSONLossy(AbstractOutput)
. The data that gets lost are the type of numbers, floating point numbers and the information whether or not theString
was previously aCharacter
.- 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 withparseJSON(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 JSONObjectOutput.toJSON(AbstractOutput)
instead ofObjectOutput.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 aByte
{"@short":0} will be interpreted as aShort
{"@int":0} will be interpreted as anInteger
{"@long":0} will be interpreted as aLong
{"@bint":0} will be interpreted as aBigInteger
{"@char":""} will be interpreted as aCharacter
{"@float":0.0} will be interpreted as aFloat
{"@double":0.0} will be interpreted as aDouble
{"@bdecimal":0.0} will be interpreted as aBigDecimal
You can find more information in the classesYAPIONMap
,YAPIONPointer
andYAPIONValue
. These classes have the methodObjectOutput.toJSON(AbstractOutput)
andObjectOutput.toJSONLossy(AbstractOutput)
overridden with a specific implementation for these types. The difference between those methods should be theYAPIONValue
implementation as it tries to not lose any data withYAPIONValue.toJSON(AbstractOutput)
and will discard some data by usingYAPIONValue.toJSONLossy(AbstractOutput)
. The data that gets lost are the type of numbers, floating point numbers and the information whether or not theString
was previously aCharacter
.- 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.0Parses 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
-
setReferenceFunction
public YAPIONParser setReferenceFunction(@NonNull @NonNull ReferenceFunction referenceFunction)
-
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 byparse()
- Returns:
- the YAPIONObject
-
-