// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.openqa.selenium.json;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.io.StringWriter;
import java.io.UncheckedIOException;
import java.io.Writer;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;
import org.jspecify.annotations.Nullable;
import org.openqa.selenium.internal.Require;
/**
* The Json class is the entrypoint for the JSON processing features of the Selenium API.
* These features include:
*
*
*
Built-in JSON deserialization to primitives and collections from the standard types shown
* below.
*
Facilities to deserialize JSON to custom data types:
*
*
Classes that declare a {@code fromJson(T)} static method, where T is any of
* the standard types shown below.
*
Classes that declare a {@code fromJson(JsonInput)} static method.
* NOTE: Objects deserialized via a {@code fromJson} static method can be
* immutable.
*
Classes that declare a constructor whose parameter names are available at runtime.
*
* NOTE: Constructor parameter names are only available if they are present in
* the class file, such as when the class is compiled with {@code javac -parameters}.
* Constructor parameter names must match the corresponding JSON field names. Parameters
* of type {@link java.util.Optional Optional} are not required.
*
Classes that declare setter methods adhering to the JavaBean
* specification.
* NOTE: Deserialized {@code JavaBean} objects are mutable, which may be
* undesirable.
*
*
Built-in JSON serialization from primitives and collections from the standard types shown
* below.
*
Facilities to serialize custom data types to JSON:
*
*
Classes that declare a {@code toJson()} method returning a primitive or collection
* from the standard types shown below.
*
Classes that declare getter methods adhering to the {@code JavaBean} specification.
*
*
*
* The standard types supported by built-in processing:
*
*
*
* You can serialize objects for which no explicit coercer has been specified, and the Json
* API will use a generic process to provide best-effort JSON output. For the most predictable
* results, though, it's best to provide a {@code toJson()} method for the Json API to use
* for serialization. This is especially beneficial for objects that contain transient properties
* that should be omitted from the JSON output.
*
*
You can deserialize objects for which no explicit handling has been defined. Note that the
* data type of the result will be {@code Map}, which means that you'll need to perform
* type checking and casting every time you extract an entry value from the result. For this reason,
* it's best to declare either a type-specific {@code fromJson()} method or a constructor with
* runtime-visible parameter names in every type you need to deserialize.
*
* @see JsonTypeCoercer
* @see JsonInput
* @see JsonOutput
*/
public class Json {
/**
* The value of {@code Content-Type} headers for HTTP requests and responses with JSON entities
*/
public static final String JSON_UTF_8 = "application/json; charset=utf-8";
/** Specifier for {@code List