Class JsonpUtils

java.lang.Object
co.elastic.clients.json.JsonpUtils

public class JsonpUtils extends Object
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static int
    Deprecated.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    ensureAccepts(JsonpDeserializer<?> deserializer, jakarta.json.stream.JsonParser parser, jakarta.json.stream.JsonParser.Event event)
     
    static void
    ensureCustomVariantsAllowed(jakarta.json.stream.JsonParser parser, JsonpMapper mapper)
     
    static void
    expectEvent(jakarta.json.stream.JsonParser parser, jakarta.json.stream.JsonParser.Event expected, jakarta.json.stream.JsonParser.Event event)
     
    static String
    expectKeyName(jakarta.json.stream.JsonParser parser, jakarta.json.stream.JsonParser.Event event)
     
    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.
    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.
    static int
    Get the maximum length of the JSON representation of a JsonpSerializable in the result of its toString() method.
    static void
    maxToStringLength(int length)
    Set the maximum length of the JSON representation of a JsonpSerializable in the result of its toString() method.
    static jakarta.json.stream.JsonParser
    objectParser(jakarta.json.JsonObject object, JsonpMapper mapper)
    Create a parser that traverses a JSON object
    static jakarta.json.spi.JsonProvider
    Get a JsonProvider instance.
    static <T> void
    serialize(T value, jakarta.json.stream.JsonGenerator generator, JsonpSerializer<T> serializer, JsonpMapper mapper)
     
    static void
    serializeDoubleOrNull(jakarta.json.stream.JsonGenerator generator, double value, double defaultValue)
     
    static void
    serializeIntOrNull(jakarta.json.stream.JsonGenerator generator, int value, int defaultValue)
     
    static void
    skipValue(jakarta.json.stream.JsonParser parser)
    Skip the value at the next position of the parser.
    static void
    skipValue(jakarta.json.stream.JsonParser parser, jakarta.json.stream.JsonParser.Event event)
    Skip the value at the current position of the parser.
    static String
     
    static String
    Renders a JsonpSerializable as a string by serializing it to JSON, prefixed by the class name.
    Renders a JsonpSerializable as a string in a destination StringBuilderby serializing it to JSON.
    Renders a JsonpSerializable as a string in a destination StringBuilderby serializing it to JSON.
    static String
    toString(jakarta.json.JsonValue value)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • JsonpUtils

      public JsonpUtils()
  • Method Details

    • provider

      public static jakarta.json.spi.JsonProvider provider()
      Get a JsonProvider instance. 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.
    • 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.
    • 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).
    • objectParser

      public static jakarta.json.stream.JsonParser objectParser(jakarta.json.JsonObject object, JsonpMapper mapper)
      Create a parser that traverses a JSON object
    • toString

      public static String toString(jakarta.json.JsonValue value)
    • 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

      public static String toString(JsonpSerializable value)
      Renders a JsonpSerializable as 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's toString() 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 a JsonpSerializable in the result of its toString() method. The default is 10k characters.
    • maxToStringLength

      public static int maxToStringLength()
      Get the maximum length of the JSON representation of a JsonpSerializable in the result of its toString() method. The default is 10k characters.
    • toString

      public static StringBuilder toString(JsonpSerializable value, JsonpMapper mapper, StringBuilder dest)
      Renders a JsonpSerializable as a string in a destination StringBuilderby serializing it to JSON.

      The size of the string is limited to maxToStringLength().

      Returns:
      the dest parameter, for chaining.
      See Also:
    • toJsonString

      public static String toJsonString(JsonpSerializable value, JsonpMapper mapper)
    • toString

      public static StringBuilder toString(JsonpSerializable value, StringBuilder dest)
      Renders a JsonpSerializable as a string in a destination StringBuilderby serializing it to JSON. Any object of an application-specific class in the object graph is rendered using that object's toString() representation as a JSON string value.

      The size of the string is limited to maxToStringLength().

      Returns:
      the dest parameter, for chaining.
      See Also: