Package jsonable
- Package jsonable
enum ConstraintValidation
Represents the result of semantic validation for a Jsonable value.
Fail
Fail(String)
- Description: Indicates validation failure and carries the failure message.
- Parameters:
String:String, The validation error message.
Pass
Pass
- Description: Indicates validation success.
struct FieldSchema
Describes one field in an object schema.
name: field name in JSON.description: human-readable field description.typeSchema: schema of the field value.required: whether the field is required in JSON.constraints: semantic constraint expressions attached to the field.
interface FromJsonValue
func fromJsonValue
static func fromJsonValue(json: JsonValue): T
- Description: Deserialize from a Json value.
- Parameters:
json:JsonValue, The Json value to deserialize from.
interface Jsonable
func getTypeSchema
static func getTypeSchema(): TypeSchema
- Description: Get the type schema of T.
func validate
func validate(): ConstraintValidation
- Description: Validates semantic constraints on the value.
- Notes:
@jsonablegenerated types implement this automatically.- Constraint checks declared by
@constraint[...]are evaluated here. fromJsonValueis expected to reject invalid values when validation fails.
class JsonableException
func init
public init(msg: String)
- Description: Initializes a new instance of JsonableException with a specified error message.
- Parameters:
msg:String, The error message that explains the reason for the exception.
interface ToJsonValue
func toJsonValue
func toJsonValue(): JsonValue
- Description: Converts the implementing type to a JsonValue.
enum TypeSchema
Arr
Arr(TypeSchema)
- Description: Represents an array type with elements of the specified TypeSchema.
- Parameters:
TypeSchema:TypeSchema, The schema of the array elements.
Boolean
Boolean
- Description: Represents a boolean type.
Enum
Enum(Array<String>)
- Description: Represents an enumeration type with the specified possible values.
- Parameters:
Array<String>:Array<String>, The list of possible string values for the enumeration.
Float
Float
- Description: Represents a floating-point number type.
Int
Int
- Description: Represents an integer type.
Obj
Obj(Array<FieldSchema>)
- Description: Represents an object type with the specified fields.
- Parameters:
Array<FieldSchema>:Array<FieldSchema>, The list of fields in the object.
Str
Str
- Description: Represents a string type.
func toJsonValue
override public func toJsonValue(): JsonValue
- Description: Converts the TypeSchema to a JsonValue.
func toString
override public func toString(): String
- Description: Converts the TypeSchema to a JSON string.