JsonConfigParser

class JsonConfigParser(json: JsonObject)

A helper class for parsing JSON configuration with error handling.

Parameters

json

The JSON object containing the configuration.

Constructors

Link copied to clipboard
constructor(json: JsonObject)

Functions

Link copied to clipboard

Parses an optional Map<String, String> field from the JSON object.

Link copied to clipboard
fun logLevel(default: Logger = Logger.NONE): Logger

Parses a log level from the JSON log field.

Link copied to clipboard
inline fun <T> optional(key: String, default: T): T

Returns the value for key decoded as type T, or default if the key is absent.

Link copied to clipboard
inline fun <T> required(key: String): T

Returns the value for key decoded as type T.

Link copied to clipboard

Parses a scope set from the JSON object, accepting either a comma-separated string or an array of strings. If the field is a string, it is split on commas to create the set. If the field is an array, each element must be a string. If the field is missing, a JsonConfigError.MissingRequiredField is thrown. If the field is present but not a string or array of strings, a JsonConfigError.InvalidType is thrown.

Link copied to clipboard
fun timeoutMillis(default: Long): Long

Parses a timeout value in milliseconds from the JSON object. If the field is missing, returns the provided default value. If the field is present but not a long integer, a JsonConfigError.InvalidType is thrown.