JSON processing library for Selenium WebDriver providing serialization and deserialization capabilities
npx @tessl/cli install tessl/maven-org-seleniumhq-selenium--selenium-json@4.33.0Selenium 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.
org.seleniumhq.selenium:selenium-json:4.33.0import 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;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);Selenium JSON is built around several key components:
JsonInput and JsonOutput for memory-efficient, streaming JSON processingThe library supports multiple serialization patterns including JavaBean conventions, static fromJson/toJson methods, and custom TypeCoercer implementations for maximum flexibility.
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;
}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);
}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);
}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
}// 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;public class JsonException extends WebDriverException {
public JsonException(String message);
public JsonException(Throwable cause);
public JsonException(String message, Throwable cause);
}Standard Java Types (Built-in Processing):
Boolean, Byte, Double, Float, Integer, Long, ShortList, Set, ArraysMap, String, Enum, URI, URL, UUID, Instant, Date, FileCustom Object Support:
fromJson(T) static methodsfromJson(JsonInput) static methodstoJson() methodsasMap() or toMap() methods