Record Class JSONValue

java.lang.Object
java.lang.Record
com.github.nedelis.jc4j.jsonvalue.JSONValue

public record JSONValue(Object value) extends Record
This class is used to wrap a json value; After wrapping a json value you can call toJavaValue(Object) which will return you converted JSONValue
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an instance of a JSONValue record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    objectsMapToJsonValuesMap(@NotNull Map<String,?> objectsMap)
    Converts map of objects to a map of JSON values
    static List<JSONValue>
    objectsToJsonValues(@NotNull List<?> values)
    Converts list of objects to a list of JSON values
    static @NotNull JSONValue
    of(Object value)
    Shortcut for JSONValue constructor
    <T> T
    toJavaValue(@NotNull IJSONValueType<T> type)
    Converting some json value into its representation in java; if value can't be converted, returns null
    <T> T
    toJavaValue(T def)
    Converting some json value into its representation in java; if value can't be converted, returns the given default value
    final String
    Returns a string representation of this record class.
    Returns the value of the value record component.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • JSONValue

      public JSONValue(Object value)
      Creates an instance of a JSONValue record class.
      Parameters:
      value - the value for the value record component
  • Method Details

    • of

      @Contract("_ -> new") @NotNull public static @NotNull JSONValue of(Object value)
      Shortcut for JSONValue constructor
      Parameters:
      value - some json value
      Returns:
      new JSONValue
    • objectsToJsonValues

      public static List<JSONValue> objectsToJsonValues(@NotNull @NotNull List<?> values)
      Converts list of objects to a list of JSON values
      Parameters:
      values - values to convert
      Returns:
      list of JSON values
    • objectsMapToJsonValuesMap

      public static Map<String,JSONValue> objectsMapToJsonValuesMap(@NotNull @NotNull Map<String,?> objectsMap)
      Converts map of objects to a map of JSON values
      Parameters:
      objectsMap - objects map to convert
      Returns:
      map of JSON values
    • toJavaValue

      public <T> T toJavaValue(T def)
      Converting some json value into its representation in java; if value can't be converted, returns the given default value
      Type Parameters:
      T - specifies which type the java value will be
      Parameters:
      def - default value that will be returned if the conversion failed; specifies the "T"
      Returns:
      converted json value
    • toJavaValue

      public <T> T toJavaValue(@NotNull @NotNull IJSONValueType<T> type)
      Converting some json value into its representation in java; if value can't be converted, returns null
      Type Parameters:
      T - specifies which type the java value will be
      Parameters:
      type - converter
      Returns:
      converted json value
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • value

      public Object value()
      Returns the value of the value record component.
      Returns:
      the value of the value record component