Class Json

java.lang.Object
dev.langchain4j.internal.Json

public class Json extends Object
A utility class for JSON.
  • Method Details

    • toJson

      public static String toJson(Object o)
      Convert the given object to JSON.
      Parameters:
      o - the object to convert.
      Returns:
      the JSON string.
    • fromJson

      public static <T> T fromJson(String json, Class<T> type)
      Convert the given JSON string to an object of the given type.
      Type Parameters:
      T - the type of the object.
      Parameters:
      json - the JSON string.
      type - the type of the object.
      Returns:
      the object.
    • toInputStream

      public static InputStream toInputStream(Object o, Class<?> type) throws IOException
      Convert the given object to an InputStream.
      Parameters:
      o - the object to convert.
      type - the type of the object.
      Returns:
      the InputStream.
      Throws:
      IOException - if an I/O error occurs.