Package co.elastic.clients.json
Class JsonpUtils
java.lang.Object
co.elastic.clients.json.JsonpUtils
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcopy(jakarta.json.stream.JsonParser parser, jakarta.json.stream.JsonGenerator generator) Copy the JSON value at the current parser location to a JSON generator.static voidcopy(jakarta.json.stream.JsonParser parser, jakarta.json.stream.JsonGenerator generator, jakarta.json.stream.JsonParser.Event event) Copy the JSON value at the current parser location to a JSON generator.static voidensureAccepts(JsonpDeserializer<?> deserializer, jakarta.json.stream.JsonParser parser, jakarta.json.stream.JsonParser.Event event) static voidensureCustomVariantsAllowed(jakarta.json.stream.JsonParser parser, JsonpMapper mapper) static voidexpectEvent(jakarta.json.stream.JsonParser parser, jakarta.json.stream.JsonParser.Event expected, jakarta.json.stream.JsonParser.Event event) static StringexpectKeyName(jakarta.json.stream.JsonParser parser, jakarta.json.stream.JsonParser.Event event) static jakarta.json.stream.JsonParser.EventexpectNextEvent(jakarta.json.stream.JsonParser parser, jakarta.json.stream.JsonParser.Event expected) Advances the parser to the next event and checks that this even is the expected one.static <Variant> Map.Entry<Variant,jakarta.json.stream.JsonParser> findVariant(Map<String, Variant> variants, jakarta.json.stream.JsonParser parser, JsonpMapper mapper) In union types, find the variant to be used by looking up property names in the JSON stream until we find one that uniquely identifies the variant.static jakarta.json.stream.JsonParserjsonValueParser(jakarta.json.JsonValue value, JsonpMapper mapper) Create a parser that traverses a JSON valuelookAheadFieldValue(String name, String defaultValue, jakarta.json.stream.JsonParser parser, JsonpMapper mapper) Looks ahead a field value in the Json object from the upcoming object in a parser, which should be on the START_OBJECT event.static intGet the maximum length of the JSON representation of aJsonpSerializablein the result of itstoString()method.static voidmaxToStringLength(int length) Set the maximum length of the JSON representation of aJsonpSerializablein the result of itstoString()method.static jakarta.json.stream.JsonParserobjectParser(jakarta.json.JsonObject object, JsonpMapper mapper) Deprecated.static jakarta.json.spi.JsonProviderprovider()Get aJsonProviderinstance.static <T> voidserialize(T value, jakarta.json.stream.JsonGenerator generator, JsonpSerializer<T> serializer, JsonpMapper mapper) static voidserializeDoubleOrNull(jakarta.json.stream.JsonGenerator generator, double value, double defaultValue) static voidserializeIntOrNull(jakarta.json.stream.JsonGenerator generator, int value, int defaultValue) static voidsetProvider(jakarta.json.spi.JsonProvider provider) Sets theJsonProviderthat will be returned byJsonProvider.static voidskipValue(jakarta.json.stream.JsonParser parser) Skip the value at the next position of the parser.static voidskipValue(jakarta.json.stream.JsonParser parser, jakarta.json.stream.JsonParser.Event event) Skip the value at the current position of the parser.static jakarta.json.spi.JsonProviderGet the system'sJsonProviderinstance return byServiceLoader.static StringtoJsonString(Object value, JsonpMapper mapper) static StringtoString(JsonpSerializable value) Renders aJsonpSerializableas a string by serializing it to JSON, prefixed by the class name.static StringBuildertoString(JsonpSerializable value, JsonpMapper mapper, StringBuilder dest) Renders aJsonpSerializableas a string in a destinationStringBuilderby serializing it to JSON.static StringBuildertoString(JsonpSerializable value, StringBuilder dest) Renders aJsonpSerializableas a string in a destinationStringBuilderby serializing it to JSON.static StringtoString(jakarta.json.JsonValue value)
-
Field Details
-
MAX_TO_STRING_LENGTH
Deprecated.
-
-
Constructor Details
-
JsonpUtils
public JsonpUtils()
-
-
Method Details
-
provider
public static jakarta.json.spi.JsonProvider provider()Get aJsonProviderinstance. This method first calls the standard `JsonProvider.provider()` that is based on the current thread's context classloader, and in case of failure tries to find a provider in other classloaders. The value is cached for subsequent calls. -
setProvider
public static void setProvider(jakarta.json.spi.JsonProvider provider) Sets theJsonProviderthat will be returned byJsonProvider. -
systemProvider
public static jakarta.json.spi.JsonProvider systemProvider()Get the system'sJsonProviderinstance return byServiceLoader. First calls the standard `JsonProvider.provider()` that is based on the current thread's context classloader, and in case of failure tries to find a provider in other classloaders. The value is cached for subsequent calls. -
expectNextEvent
public static jakarta.json.stream.JsonParser.Event expectNextEvent(jakarta.json.stream.JsonParser parser, jakarta.json.stream.JsonParser.Event expected) Advances the parser to the next event and checks that this even is the expected one.- Returns:
- the expected event
- Throws:
jakarta.json.JsonException- if an i/o error occurs (IOException would be cause of JsonException)jakarta.json.stream.JsonParsingException- if the event is not the expected one, or if the parser encounters invalid JSON when advancing to next state.NoSuchElementException- if there are no more parsing states.
-
expectEvent
public static void expectEvent(jakarta.json.stream.JsonParser parser, jakarta.json.stream.JsonParser.Event expected, jakarta.json.stream.JsonParser.Event event) -
expectKeyName
public static String expectKeyName(jakarta.json.stream.JsonParser parser, jakarta.json.stream.JsonParser.Event event) -
ensureAccepts
public static void ensureAccepts(JsonpDeserializer<?> deserializer, jakarta.json.stream.JsonParser parser, jakarta.json.stream.JsonParser.Event event) -
ensureCustomVariantsAllowed
public static void ensureCustomVariantsAllowed(jakarta.json.stream.JsonParser parser, JsonpMapper mapper) -
skipValue
public static void skipValue(jakarta.json.stream.JsonParser parser) Skip the value at the next position of the parser. -
skipValue
public static void skipValue(jakarta.json.stream.JsonParser parser, jakarta.json.stream.JsonParser.Event event) Skip the value at the current position of the parser. -
copy
public static void copy(jakarta.json.stream.JsonParser parser, jakarta.json.stream.JsonGenerator generator) Copy the JSON value at the current parser location to a JSON generator. -
copy
public static void copy(jakarta.json.stream.JsonParser parser, jakarta.json.stream.JsonGenerator generator, jakarta.json.stream.JsonParser.Event event) Copy the JSON value at the current parser location to a JSON generator. -
serialize
public static <T> void serialize(T value, jakarta.json.stream.JsonGenerator generator, @Nullable JsonpSerializer<T> serializer, JsonpMapper mapper) -
lookAheadFieldValue
public static Map.Entry<String,jakarta.json.stream.JsonParser> lookAheadFieldValue(String name, String defaultValue, jakarta.json.stream.JsonParser parser, JsonpMapper mapper) Looks ahead a field value in the Json object from the upcoming object in a parser, which should be on the START_OBJECT event.Returns a pair containing that value and a parser that should be used to actually parse the object (the object has been consumed from the original one).
-
findVariant
public static <Variant> Map.Entry<Variant,jakarta.json.stream.JsonParser> findVariant(Map<String, Variant> variants, jakarta.json.stream.JsonParser parser, JsonpMapper mapper) In union types, find the variant to be used by looking up property names in the JSON stream until we find one that uniquely identifies the variant.- Type Parameters:
Variant- the type of variant descriptors used by the caller.- Parameters:
variants- a map of variant descriptors, keyed by the property name that uniquely identifies the variant.- Returns:
- a pair containing the variant descriptor (or
nullif not found), and a parser to be used to read the JSON object.
-
objectParser
@Deprecated public static jakarta.json.stream.JsonParser objectParser(jakarta.json.JsonObject object, JsonpMapper mapper) Deprecated.Create a parser that traverses a JSON object -
jsonValueParser
public static jakarta.json.stream.JsonParser jsonValueParser(jakarta.json.JsonValue value, JsonpMapper mapper) Create a parser that traverses a JSON value -
toString
-
serializeDoubleOrNull
public static void serializeDoubleOrNull(jakarta.json.stream.JsonGenerator generator, double value, double defaultValue) -
serializeIntOrNull
public static void serializeIntOrNull(jakarta.json.stream.JsonGenerator generator, int value, int defaultValue) -
toString
Renders aJsonpSerializableas a string by serializing it to JSON, prefixed by the class name. Any object of an application-specific class in the object graph is rendered using that object'stoString()representation as a JSON string value.The size of the string is limited to
maxToStringLength().- See Also:
-
maxToStringLength
public static void maxToStringLength(int length) Set the maximum length of the JSON representation of aJsonpSerializablein the result of itstoString()method. The default is 10k characters. -
maxToStringLength
public static int maxToStringLength()Get the maximum length of the JSON representation of aJsonpSerializablein the result of itstoString()method. The default is 10k characters. -
toString
public static StringBuilder toString(JsonpSerializable value, JsonpMapper mapper, StringBuilder dest) Renders aJsonpSerializableas a string in a destinationStringBuilderby serializing it to JSON.The size of the string is limited to
maxToStringLength().- Returns:
- the
destparameter, for chaining. - See Also:
-
toJsonString
-
toString
Renders aJsonpSerializableas a string in a destinationStringBuilderby serializing it to JSON. Any object of an application-specific class in the object graph is rendered using that object'stoString()representation as a JSON string value.The size of the string is limited to
maxToStringLength().- Returns:
- the
destparameter, for chaining. - See Also:
-
maxToStringLength(int)