java.lang.Object
dev.metaschema.core.model.util.JsonUtil
Provides utility functions to support reading and writing JSON, and for
producing error and warning messages.
-
Method Summary
Modifier and TypeMethodDescriptionstatic com.fasterxml.jackson.core.JsonTokenadvanceAndAssert(com.fasterxml.jackson.core.JsonParser parser, URI resource, com.fasterxml.jackson.core.JsonToken expectedToken) Advance the token stream, then ensure that the current token is the one expected.static com.fasterxml.jackson.core.JsonTokenadvanceTo(com.fasterxml.jackson.core.JsonParser parser, URI resource, com.fasterxml.jackson.core.JsonToken token) Advance the parser to the next location matching the provided token.static com.fasterxml.jackson.core.JsonTokenassertAndAdvance(com.fasterxml.jackson.core.JsonParser parser, URI resource, com.fasterxml.jackson.core.JsonToken expectedToken) Ensure that the current token is the one expected and then advance the token stream.static voidassertCurrent(com.fasterxml.jackson.core.JsonParser parser, URI resource, com.fasterxml.jackson.core.JsonToken... expectedTokens) Ensure that the current token is one of the provided tokens.static CharSequencegenerateLocationMessage(com.fasterxml.jackson.core.JsonLocation location, URI resource) Generate a location string for the current location in the JSON token stream.static CharSequencegenerateLocationMessage(com.fasterxml.jackson.core.JsonParser parser, URI resource) Generate a location string for the current location in the JSON token stream.static com.fasterxml.jackson.core.JsonTokenskipNextValue(com.fasterxml.jackson.core.JsonParser parser, URI resource) Skip the next JSON value in the stream.static org.json.JSONObjectParse the input stream into a JSON object.static org.json.JSONObjecttoJsonObject(Reader reader) Parse the reader into a JSON object.static StringtoString(com.fasterxml.jackson.core.JsonLocation location) Generate an informational string describing the providedlocation.static StringGenerate an informational string describing the token at the current location of the providedparser.
-
Method Details
-
toJsonObject
Parse the input stream into a JSON object.- Parameters:
is- the input stream to parse- Returns:
- the JSON object
-
toJsonObject
Parse the reader into a JSON object.- Parameters:
reader- the reader to parse- Returns:
- the JSON object
-
toString
@NonNull public static String toString(@NonNull com.fasterxml.jackson.core.JsonParser parser, @NonNull URI resource) throws IOException Generate an informational string describing the token at the current location of the providedparser.- Parameters:
parser- the JSON parserresource- the resource being parsed- Returns:
- the informational string
- Throws:
IOException- if an error occurred while getting the information from the parser
-
toString
Generate an informational string describing the providedlocation.- Parameters:
location- a JSON parser location- Returns:
- the informational string
-
advanceTo
@Nullable public static com.fasterxml.jackson.core.JsonToken advanceTo(@NonNull com.fasterxml.jackson.core.JsonParser parser, @NonNull URI resource, @NonNull com.fasterxml.jackson.core.JsonToken token) throws IOException Advance the parser to the next location matching the provided token.- Parameters:
parser- the JSON parserresource- the resource being parsedtoken- the expected token- Returns:
- the current token or
nullif no tokens remain in the stream - Throws:
IOException- if an error occurred while parsing the JSON
-
skipNextValue
@Nullable public static com.fasterxml.jackson.core.JsonToken skipNextValue(@NonNull com.fasterxml.jackson.core.JsonParser parser, @NonNull URI resource) throws IOException Skip the next JSON value in the stream.- Parameters:
parser- the JSON parserresource- the resource being parsed- Returns:
- the current token or
nullif no tokens remain in the stream - Throws:
IOException- if an error occurred while parsing the JSON
-
assertCurrent
public static void assertCurrent(@NonNull com.fasterxml.jackson.core.JsonParser parser, @NonNull URI resource, @NonNull com.fasterxml.jackson.core.JsonToken... expectedTokens) Ensure that the current token is one of the provided tokens.Note: This uses a Java assertion to support debugging in a whay that doesn't impact parser performance during production operation.
- Parameters:
parser- the JSON parserresource- the resource being parsedexpectedTokens- the tokens for which one is expected to match against the current token
-
assertAndAdvance
@Nullable public static com.fasterxml.jackson.core.JsonToken assertAndAdvance(@NonNull com.fasterxml.jackson.core.JsonParser parser, @NonNull URI resource, @NonNull com.fasterxml.jackson.core.JsonToken expectedToken) throws IOException Ensure that the current token is the one expected and then advance the token stream.- Parameters:
parser- the JSON parserresource- the resource being parsedexpectedToken- the expected token- Returns:
- the next token
- Throws:
IOException- if an error occurred while reading the token stream
-
advanceAndAssert
@Nullable public static com.fasterxml.jackson.core.JsonToken advanceAndAssert(@NonNull com.fasterxml.jackson.core.JsonParser parser, @NonNull URI resource, @NonNull com.fasterxml.jackson.core.JsonToken expectedToken) throws IOException Advance the token stream, then ensure that the current token is the one expected.- Parameters:
parser- the JSON parserresource- the resource being parsedexpectedToken- the expected token- Returns:
- the next token
- Throws:
IOException- if an error occurred while reading the token stream
-
generateLocationMessage
@NonNull public static CharSequence generateLocationMessage(@NonNull com.fasterxml.jackson.core.JsonParser parser, @NonNull URI resource) Generate a location string for the current location in the JSON token stream.- Parameters:
parser- the JSON parserresource- the resource being parsed- Returns:
- the location string
-
generateLocationMessage
@NonNull public static CharSequence generateLocationMessage(@NonNull com.fasterxml.jackson.core.JsonLocation location, @NonNull URI resource) Generate a location string for the current location in the JSON token stream.- Parameters:
location- a JSON token stream locationresource- the resource being parsed- Returns:
- the location string
-