Package jsonvalues

Class TryObj


  • public final class TryObj
    extends Object
    Computation that parses a string into a JsObj and may either result in a MalformedJson exception or a successfully parsed object.
    • Constructor Detail

      • TryObj

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

        @EnsuresNonNull("#1")
        public TryObj​(MalformedJson error)
    • Method Detail

      • isFailure

        public boolean isFailure()
        Returns true if the parsed string is a malformed json object.
        Returns:
        true if the parsed string is a malformed json object
      • isSuccess

        public boolean isSuccess()
        Returns true if the parsed string is a well-formed json object.
        Returns:
        true if the parsed string is a well-formed json object
      • toOptional

        public Optional<JsObj> toOptional()
        Returns the computed json object wrapped in an optional if the parsed string is a well-formed json object, returning an empty optional otherwise.
        Returns:
        an Optional containing a JsObj or Optional.empty() if the given string is not a well-formed json object.
      • orElseThrow

        public JsObj orElseThrow()
                          throws MalformedJson
        Returns the computed JsObj if the parsed string is a well-formed json object, throwing an exception otherwise.
        Returns:
        a JsObj
        Throws:
        MalformedJson - if this try is a failure
      • orElse

        public JsObj orElse​(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 - supplier to be executed if the parsed string is not a well-formed json object
        Returns:
        a JsObj