Class JWObject

  • Direct Known Subclasses:
    JWKSet, JwtClaimsSet, JwtHeader

    public abstract class JWObject
    extends Object
    A base implementation class for a JSON Web object.

    Provides a set of methods which are common across JWT, JWS, JWE and JWK implementations.

    Since:
    2.0.0
    • Constructor Detail

      • JWObject

        public JWObject()
        Constructs a new, empty JWObject.
    • Method Detail

      • checkValueIsOfType

        protected void checkValueIsOfType​(Object value,
                                          Class<?> requiredClazz)
        Checks that the given value is of an assignable type from the required class.

        Will throw a JwtRuntimeException if the value is not of the required type

        Parameters:
        value - The value to check is of the required type.
        requiredClazz - The class of the required type.
        See Also:
        isValueOfType(Object, Class)
      • checkListValuesAreOfType

        protected void checkListValuesAreOfType​(List<?> value,
                                                Class<?> requiredClazz)
        Checks that the given List's type is of an assignable type from the required class.

        Will throw a JwtRuntimeException if the value is not of the required type

        Parameters:
        value - The List to check the type is of the required type.
        requiredClazz - The class of the required type.
        See Also:
        checkValueIsOfType(Object, Class)
      • isValueOfType

        protected boolean isValueOfType​(Object value,
                                        Class<?> requiredClazz)
        Checks to see if the given value is of an assignable type from the required class.
        Parameters:
        value - The value to check is of the required type.
        requiredClazz - The class of the required type.
        Returns:
        true if the value if of the required type.
        See Also:
        checkValueIsOfType(Object, Class)
      • put

        public void put​(String key,
                        Object value)
        Sets or removes the value of the specified member.

        If the value is not null, then the value is set as the value of the given key.

        Otherwise, if the value is null and the key already exist with a value assigned to it, then the key and its value will be removed. If the specified key is not defined, calling this method has no effect.

        Parameters:
        key - the Map key identifying the value to set or to remove.
        value - the object value to assign to the member.
      • get

        public JsonValue get​(String key)
        Returns the specified item value. If no such member value exists, then a JSON value containing null is returned.
        Parameters:
        key - the Map key identifying the item to return.
        Returns:
        a JSON value containing the value or null.
      • isDefined

        public boolean isDefined​(String key)
        Returns true if this JWObject contains the specified item.
        Parameters:
        key - the Map key of the item to seek.
        Returns:
        true if this JSON value contains the specified member.
      • keys

        public Set<String> keys()
        Returns the set of keys for this JWObject's values.

        The order of the resulting keys is undefined. If there are no values set, this method returns an empty set.

        Returns:
        A Set of keys.
      • toString

        public String toString()
        Returns a string representation of the JWObject. The result is guaranteed to be valid JSON object syntax.
        Overrides:
        toString in class Object
        Returns:
        A JSON String representation.
      • toJsonValue

        public JsonValue toJsonValue()
        Returns a json representation of the JWObject.
        Returns:
        A JSON representation.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object