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(java.io.InputStream inputStream)
Creates a YAPIONParser for parsing an InputStream to an YAPIONObject.YAPIONParser(java.lang.String s)
Creates a YAPIONParser for parsing an string 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.YAPIONObject
result()
Returns the YAPIONObject parsed byparse()
-
-
-
Constructor Detail
-
YAPIONParser
public YAPIONParser(java.lang.String s)
Creates a YAPIONParser for parsing an string to an YAPIONObject.- Parameters:
s
- to parse from
-
YAPIONParser
public YAPIONParser(java.io.InputStream inputStream)
Creates a YAPIONParser for parsing an InputStream to an YAPIONObject.- Parameters:
inputStream
- to parse from
-
-
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
-
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
-
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
-
-