Package jsonvalues

Class 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.
    • Constructor Detail

      • Try

        @EnsuresNonNull("#1")
        public Try​(JsObj obj)
      • Try

        @EnsuresNonNull("#1")
        public Try​(JsArray arr)
    • 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.