or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

core-processing.mdindex.mdstreaming-input.mdstreaming-output.mdtype-system.md
tile.json

tessl/maven-org-seleniumhq-selenium--selenium-json

JSON processing library for Selenium WebDriver providing serialization and deserialization capabilities

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/org.seleniumhq.selenium/selenium-json@4.33.x

To install, run

npx @tessl/cli install tessl/maven-org-seleniumhq-selenium--selenium-json@4.33.0

index.mddocs/

Selenium JSON

Selenium JSON is a comprehensive JSON processing library that serves as the core JSON handling component within the Selenium WebDriver ecosystem. It provides robust serialization and deserialization capabilities for converting between Java objects and JSON representations, supporting standard Java types, custom objects, and complex nested data structures with type coercion mechanisms and streaming processing.

Package Information

  • Package Name: selenium-json
  • Package Type: Maven
  • Language: Java
  • Maven Coordinates: org.seleniumhq.selenium:selenium-json:4.33.0
  • Installation: Add to Maven dependencies or include in Bazel BUILD file

Core Imports

import org.openqa.selenium.json.Json;
import org.openqa.selenium.json.JsonInput;
import org.openqa.selenium.json.JsonOutput;

For type-safe deserialization:

import org.openqa.selenium.json.TypeToken;
import org.openqa.selenium.json.PropertySetting;

Basic Usage

import org.openqa.selenium.json.Json;
import java.util.Map;
import java.util.List;

// Create JSON processor instance
Json json = new Json();

// Serialize objects to JSON
String jsonString = json.toJson(myObject);

// Deserialize JSON to specific types
MyClass obj = json.toType(jsonString, MyClass.class);

// Work with generic types using TypeToken
List<Map<String, Object>> data = json.toType(
    jsonString, 
    new TypeToken<List<Map<String, Object>>>() {}.getType()
);

// Control property setting during deserialization
MyClass obj = json.toType(jsonString, MyClass.class, PropertySetting.BY_FIELD);

Architecture

Selenium JSON is built around several key components:

  • Json Class: Main entry point providing high-level serialization/deserialization methods
  • Streaming Processors: JsonInput and JsonOutput for memory-efficient, streaming JSON processing
  • Type Coercion System: Extensible framework for converting between JSON and Java types
  • Property Setting Strategies: Configurable approaches for setting object properties during deserialization
  • Built-in Type Support: Comprehensive support for Java primitives, collections, and common types

The library supports multiple serialization patterns including JavaBean conventions, static fromJson/toJson methods, and custom TypeCoercer implementations for maximum flexibility.

Capabilities

Core JSON Processing

High-level JSON serialization and deserialization operations using the main Json class. Provides simple string-based and reader-based processing with configurable depth limits and property setting strategies.

public class Json {
    public String toJson(Object toConvert);
    public String toJson(Object toConvert, int maxDepth);
    public <T> T toType(String source, Type typeOfT);
    public <T> T toType(String source, Type typeOfT, PropertySetting setter);
    public <T> T toType(Reader source, Type typeOfT);
    public <T> T toType(Reader source, Type typeOfT, PropertySetting setter);
    public JsonInput newInput(Reader from) throws UncheckedIOException;
    public JsonOutput newOutput(Appendable to) throws UncheckedIOException;
}

Core Processing

Streaming JSON Input

Advanced JSON reading and deserialization using JsonInput for memory-efficient processing of large JSON documents. Supports custom type coercers, streaming parsing, and fine-grained control over the parsing process.

public class JsonInput implements Closeable {
    public PropertySetting propertySetting(PropertySetting setter);
    public JsonInput addCoercers(TypeCoercer<?>... coercers);
    public JsonInput addCoercers(Iterable<TypeCoercer<?>> coercers);
    public JsonType peek();
    public boolean nextBoolean();
    public String nextName();
    public Object nextNull();
    public Number nextNumber();
    public String nextString();
    public Instant nextInstant();
    public <T> T read(Type type);
    public <T> List<T> readArray(Type type);
}

Streaming Input

Streaming JSON Output

Advanced JSON writing and serialization using JsonOutput for memory-efficient generation of JSON documents. Supports pretty printing, depth control, and fine-grained control over the serialization process.

public class JsonOutput implements Closeable {
    public JsonOutput setPrettyPrint(boolean enablePrettyPrinting);
    public JsonOutput writeClassName(boolean writeClassName);
    public JsonOutput beginObject();
    public JsonOutput name(String name);
    public JsonOutput endObject();
    public JsonOutput beginArray();
    public JsonOutput endArray();
    public JsonOutput write(Object value);
    public JsonOutput write(Object value, int maxDepth);
}

Streaming Output

Type System and Coercion

Comprehensive type conversion system supporting custom type coercers, generic type handling with TypeToken, and extensible type conversion patterns for complex object hierarchies.

public abstract class TypeToken<T> {
    public Type getType();
}

public abstract class TypeCoercer<T> implements Predicate<Class<?>>, Function<Type, BiFunction<JsonInput, PropertySetting, T>> {
    public abstract boolean test(Class<?> aClass);
    public abstract BiFunction<JsonInput, PropertySetting, T> apply(Type type);
}

public enum PropertySetting {
    BY_NAME,
    BY_FIELD
}

Type System

Constants and Utilities

// Content type constant
public static final String JSON_UTF_8 = "application/json; charset=utf-8";

// Common type tokens
public static final Type LIST_OF_MAPS_TYPE = new TypeToken<List<Map<String, Object>>>() {}.getType();
public static final Type MAP_TYPE = new TypeToken<Map<String, Object>>() {}.getType();
public static final Type OBJECT_TYPE = new TypeToken<Object>() {}.getType();

// Maximum traversal depth
public static final int MAX_DEPTH = 100;

Exception Handling

public class JsonException extends WebDriverException {
    public JsonException(String message);
    public JsonException(Throwable cause);
    public JsonException(String message, Throwable cause);
}

Supported Types

Standard Java Types (Built-in Processing):

  • Primitives: Boolean, Byte, Double, Float, Integer, Long, Short
  • Collections: List, Set, Arrays
  • Standard Types: Map, String, Enum, URI, URL, UUID, Instant, Date, File

Custom Object Support:

  • Objects with fromJson(T) static methods
  • Objects with fromJson(JsonInput) static methods
  • Objects with toJson() methods
  • Objects with asMap() or toMap() methods
  • JavaBean-compliant objects with getter/setter methods