Class JSONValueType

java.lang.Object
com.github.nedelis.jc4j.jsonvalue.JSONValueType

public final class JSONValueType extends Object
This class allows you to convert any value from a json to a java value; You also can register your own java value types by using register(String, IJSONValueType)

All registered types will be stored in the TYPES; If you need to get definite IJSONValueType you can use saved constants of them

  • Field Details

  • Constructor Details

    • JSONValueType

      public JSONValueType()
  • Method Details

    • register

      public static <T> IJSONValueType<T> register(String name, IJSONValueType<T> type)
      Registers a new IJSONValueType (puts it in TYPES and returns it)
      Type Parameters:
      T - specifies the type of returned IJSONValueType
      Parameters:
      name - name that will be associated with new IJSONValueType
      type - IJSONValueType that will be registered
      Returns:
      provided IJSONValueType
    • toJavaValue

      public static <T> T toJavaValue(Object jsonValue, T def)
      This method tries to find correct JSONValueType for "T def" and converts given value to java value; If it can't find correct JSONValueType for "T def", then it'll issue a warning and return given default value
      Type Parameters:
      T - specifies which type the java value will be
      Parameters:
      jsonValue - value to convert
      def - default value that will be returned if conversion failed; specifies the "T"
      Returns:
      converted json value
    • toJavaValue

      public static <T> T toJavaValue(Object jsonValue, @NotNull @NotNull IJSONValueType<T> valueType)
    • toJavaValue

      public static <T> T toJavaValue(Object jsonValue, T def, @NotNull @NotNull IJSONValueType<T> valueType)