Class ConverterFunctions

java.lang.Object
org.openqa.selenium.bidi.ConverterFunctions

@Beta @Internal public class ConverterFunctions extends Object
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final org.openqa.selenium.json.Json
    The shared Json every generated BiDi type is decoded through, including via fromMap(Class) and — through Command's Type-based constructor — every plain command result too, so a command and an event never disagree on how strictly to accept the same wire shape.
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> Function<Map<String,Object>, T>
    fromMap(Class<T> type)
    Returns a function that deserializes a Map<String, Object> event payload (or a nested union variant, already parsed into a map) into an instance of type via Json.convert(Object, Type) — the same single-round-trip primitive map(String, Type) uses, rather than a second hand-rolled toJson/JsonInput pair.
    static <X> Function<@Nullable Object, X>
    map(String keyName, Type typeOfX)
    Build a Command result mapper for the common case where the useful value is a single field of the response's result object.

    Methods inherited from class Object

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

    • JSON

      public static final org.openqa.selenium.json.Json JSON
      The shared Json every generated BiDi type is decoded through, including via fromMap(Class) and — through Command's Type-based constructor — every plain command result too, so a command and an event never disagree on how strictly to accept the same wire shape. Adds StrictLongCoercer/StrictStringCoercer/StrictNumberCoercer (each rejects a value of the wrong JSON type for a String/integer/number field, instead of silently converting it — e.g. a numeric url or a quoted timeOrigin) and StaticInitializerCoercer ahead of EnumCoercer (so a generated enum's exact-match fromJson runs, not the case-insensitive default) — all scoped to this instance only.
  • Method Details

    • map

      public static <X> Function<@Nullable Object, X> map(String keyName, Type typeOfX)
      Build a Command result mapper for the common case where the useful value is a single field of the response's result object.

      The returned function is applied to a command's result value, which Connection has already parsed into a Map<String, Object>. It reads keyName from that map and deserializes it to typeOfX via Json.convert(Object, Type), without re-parsing any JSON text. Both the result and the field are required: a missing result or a null/absent field is an error.

      Parameters:
      keyName - the field to read from the command's result object
      typeOfX - the type to deserialize that field to (class or TypeToken)
    • fromMap

      public static <T> Function<Map<String,Object>, T> fromMap(Class<T> type)
      Returns a function that deserializes a Map<String, Object> event payload (or a nested union variant, already parsed into a map) into an instance of type via Json.convert(Object, Type) — the same single-round-trip primitive map(String, Type) uses, rather than a second hand-rolled toJson/JsonInput pair.