Class JsonParser
java.lang.Object
de.monticore.symboltable.serialization.JsonParser
Parses serialized JSON Strings into an intermediate JSON data structure. This data structure can
then be used, e.g., to build Java objects with their builders.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidDisables object member tracing.static voidIf object member tracing is enabled, getter-methods of Json objects are tracked to identify, if any members have been forgotten during deserializationstatic JsonElementParses a given String encoded in JSON to aJsonElement.static JsonElementparses any json using the passed lexer.protected static JsonArrayparseJsonArray(JsonLexer lexer) Parses a Json array by using the passed lexerstatic JsonArrayparseJsonArray(String json) Parses a given String encoded in JSON to aJsonArray.protected static JsonObjectparseJsonObject(JsonLexer lexer) Parses a Json Object with the passed lexerstatic JsonObjectparseJsonObject(String json) Parses a given String encoded in JSON to aJsonObject.protected static JsonTokenpeekNextNonWhiteSpace(JsonLexer lexer) reads all whitespace tokens until the next non-whitespace token.protected static JsonTokenpollNextNonWhiteSpace(JsonLexer lexer) reads all whitespace tokens until the next non-whitespace token.
-
Constructor Details
-
JsonParser
public JsonParser()
-
-
Method Details
-
parse
Parses a given String encoded in JSON to aJsonElement. This method should be used if the Json type (i.e., Object, Array,...) of the encoded JSON is unclear.- Parameters:
s-- Returns:
-
parseJsonObject
Parses a given String encoded in JSON to aJsonObject. Parsing of the String fails with an error if the encoded String cannot be parsed into a Json object.- Parameters:
json-- Returns:
-
parseJsonArray
Parses a given String encoded in JSON to aJsonArray. Parsing of the String fails with an error if the encoded String cannot be parsed into a Json array.- Parameters:
json-- Returns:
-
parseJson
parses any json using the passed lexer.- Parameters:
lexer-- Returns:
-
parseJsonObject
Parses a Json Object with the passed lexer- Parameters:
lexer-- Returns:
-
parseJsonArray
Parses a Json array by using the passed lexer- Parameters:
lexer-- Returns:
-
enableObjectMemberTracing
public static void enableObjectMemberTracing()If object member tracing is enabled, getter-methods of Json objects are tracked to identify, if any members have been forgotten during deserialization -
disableObjectMemberTracing
public static void disableObjectMemberTracing()Disables object member tracing.- See Also:
-
peekNextNonWhiteSpace
reads all whitespace tokens until the next non-whitespace token. This is returned, but not consumed. If the method is called when the lexer has already reached the end of the document, it returns "null". If the end of the document occurs during consumption of whitespaces, a whitespace token is returned.- Parameters:
lexer-- Returns:
-
pollNextNonWhiteSpace
reads all whitespace tokens until the next non-whitespace token. This is returned and consumed. If the method is called when the lexer has already reached the end of the document, it returns "null". If the end of the document occurs during consumption of whitespaces, a whitespace token is returned.- Parameters:
lexer-- Returns:
-