Package jsonvalues
Class Try
- java.lang.Object
-
- jsonvalues.Try
-
public final class Try extends Object
Computation that parses a string into a Json and may either result in a MalformedJson exception or a successfully parsed json.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description JsArray
arrOrElse(Supplier<JsArray> other)
Returns the computed JsArray if the parsed string is a well-formed json array, returning the JsArray given by the supplier otherwise.JsArray
arrOrElseThrow()
Returns the computed JsArray if the parsed string is a well-formed json array, throwing a MalformedJson exception otherwise.boolean
isFailure()
Returns true if the parsed string is a malformed json.boolean
isSuccess()
Returns true if the parsed string is a well-formed json.JsObj
objOrElse(Supplier<JsObj> other)
Returns the computed JsObj if the parsed string is a well-formed json object, returning the JsObj given by the supplier otherwise.JsObj
objOrElseThrow()
Returns the computed JsObj if the parsed string is a well-formed json object, throwing a MalformedJson exception otherwise.Json<?>
orElseThrow()
Returns the computed Json if the parsed string is a well-formed json, throwing a MalformedJson exception otherwise.Optional<Json<?>>
toOptional()
Returns the computed Json wrapped in an optional if the parsed string is a well-formed json, returning an empty optional otherwise.
-
-
-
Method Detail
-
isFailure
public boolean isFailure()
Returns true if the parsed string is a malformed json.- Returns:
- true if the parsed string is a malformed json
-
isSuccess
public boolean isSuccess()
Returns true if the parsed string is a well-formed json.- Returns:
- true if the parsed string is a well-formed json
-
objOrElseThrow
public JsObj objOrElseThrow() throws MalformedJson
Returns the computed JsObj if the parsed string is a well-formed json object, throwing a MalformedJson exception otherwise.- Returns:
- a JsObj
- Throws:
MalformedJson
- if the parsed string is not a well-formed json object
-
arrOrElseThrow
public JsArray arrOrElseThrow() throws MalformedJson
Returns the computed JsArray if the parsed string is a well-formed json array, throwing a MalformedJson exception otherwise.- Returns:
- a JsArray
- Throws:
MalformedJson
- if the parsed string is not a well-formed json array
-
orElseThrow
public Json<?> orElseThrow() throws MalformedJson
Returns the computed Json if the parsed string is a well-formed json, throwing a MalformedJson exception otherwise.- Returns:
- a Json
- Throws:
MalformedJson
- if the parsed string is not a well-formed json
-
arrOrElse
public JsArray arrOrElse(Supplier<JsArray> other)
Returns the computed JsArray if the parsed string is a well-formed json array, returning the JsArray given by the supplier otherwise.- Parameters:
other
- the supplier- Returns:
- a JsArray
-
objOrElse
public JsObj objOrElse(Supplier<JsObj> other)
Returns the computed JsObj if the parsed string is a well-formed json object, returning the JsObj given by the supplier otherwise.- Parameters:
other
- the supplier- Returns:
- a JsArray
-
toOptional
public Optional<Json<?>> toOptional()
Returns the computed Json wrapped in an optional if the parsed string is a well-formed json, returning an empty optional otherwise.- Returns:
- Optional.empty() if the parsed string is not a well-formed json, returning an Optional containing the computed Json otherwise.
-
-