Package com.openai.core
Class JsonValue
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interface
JsonValue.Visitor
An interface that defines how to map each variant state of a JsonValue to a value of type R.
public final class
JsonValue.Deserializer
-
Method Summary
Modifier and Type Method Description final <R extends Any> R
convert(TypeReference<R> type)
final <R extends Any> R
convert(Class<R> type)
final <R extends Any> R
accept(JsonValue.Visitor<R> visitor)
Returns the result of calling the visitor method corresponding to this value's variant. final static JsonValue
from(Object value)
Converts the given value to a JsonValue. final static JsonValue
fromJsonNode(JsonNode node)
Returns a JsonValue converted from the given Jackson JsonNode. -
Methods inherited from class com.openai.core.JsonField
accept, asArray, asBoolean, asKnown, asNumber, asObject, asString, asStringOrThrow, asUnknown, isMissing, isNull
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Method Detail
-
accept
final <R extends Any> R accept(JsonValue.Visitor<R> visitor)
Returns the result of calling the visitor method corresponding to this value's variant.
-
from
final static JsonValue from(Object value)
Converts the given value to a JsonValue.
This method works best on primitive types, List values, Map values, and nested combinations of these. For example:
// Create primitive JSON values JsonValue nullValue = JsonValue.from(null); JsonValue booleanValue = JsonValue.from(true); JsonValue numberValue = JsonValue.from(42); JsonValue stringValue = JsonValue.from("Hello World!"); // Create a JSON array value equivalent to `["Hello", "World"]` JsonValue arrayValue = JsonValue.from(List.of("Hello", "World")); // Create a JSON object value equivalent to `{ "a": 1, "b": 2 }` JsonValue objectValue = JsonValue.from(Map.of( "a", 1, "b", 2 )); // Create an arbitrarily nested JSON equivalent to: // { // "a": [1, 2], // "b": [3, 4] // } JsonValue complexValue = JsonValue.from(Map.of( "a", List.of(1, 2), "b", List.of(3, 4) ));
-
fromJsonNode
final static JsonValue fromJsonNode(JsonNode node)
Returns a JsonValue converted from the given Jackson JsonNode.
-
-
-
-