DSON class abstract

Data Serialization Object Notation (DSON) system for Vaden.

DSON is a core component of the Vaden framework that handles serialization and deserialization of data transfer objects (DTOs). It provides a type-safe way to convert between JSON data and strongly-typed Dart objects.

The DSON system maintains mappings between types and their serialization/deserialization functions, allowing for automatic conversion of request and response bodies in controllers.

Implementations of DSON should provide the necessary mappings for all DTOs used in the application by implementing the getMaps() method.

Example implementation:

@Component()
class AppDSON extends DSON {
  @override
  (Map<Type, FromJsonFunction>, Map<Type, ToJsonFunction>, Map<Type, ToOpenApiNormalMap>) getMaps() {
    return (
      <Type, FromJsonFunction>{
        UserDTO: (json) => UserDTO.fromJson(json),
        ProductDTO: (json) => ProductDTO.fromJson(json),
      },
      <Type, ToJsonFunction>{
        UserDTO: (user) => (user as UserDTO).toJson(),
        ProductDTO: (product) => (product as ProductDTO).toJson(),
      },
      <Type, ToOpenApiNormalMap>{
        UserDTO: {
          'type': 'object',
          'properties': {
            'id': {'type': 'string'},
            'name': {'type': 'string'},
            'email': {'type': 'string'},
          },
          'required': ['id', 'name', 'email'],
        },
        // Other OpenAPI schemas...
      },
    );
  }
}

Constructors

DSON()
Creates a new DSON instance and initializes the serialization maps.

Properties

apiEntries Map<Type, ToOpenApiNormalMap>
Returns all registered OpenAPI schemas.
no setter
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

addFromJson<T>(FromJsonFunction<T> fromJson) → void
addToJson<T>(ToJsonFunction toJson) → void
addToOpenApi<T>(ToOpenApiNormalMap toOpenApi) → void
fromJson<T>(Map<String, dynamic> json) → T
Converts a JSON map to an object of type T.
fromJsonList<T>(List json) List<T>
Converts a list of JSON maps to a list of objects of type T.
getMaps() → (Map<Type, FromJsonFunction>, Map<Type, ToJsonFunction>, Map<Type, ToOpenApiNormalMap>)
Returns the mappings between types and their serialization/deserialization functions.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toJson<T>(T object) Map<String, dynamic>
Converts an object of type T to a JSON map.
toJsonByType(dynamic object, Type type) Map<String, dynamic>
toJsonList<T>(List<T> object) List<Map<String, dynamic>>
Converts a list of objects of type T to a list of JSON maps.
toOpenApi<T>() Map<String, dynamic>?
Returns the OpenAPI schema for type T.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited