dynamo_json

Creator: coderz1093

Last updated:

0 purchases

dynamo_json Image
dynamo_json Images

Languages

Categories

Add to Cart

Description:

dynamo json

dynamo_json #
A Dart build_runner to generate toDynamoJson and fromDynamoJson support methods, similar to json_serializable, specifically supporting the DynamoDB attribute values.
Installation #
Add dynamo_json to your pubspec.yaml as shown below or run dart pub add dynamo_json
dependencies:
dynamo_json: ^0.0.1
copied to clipboard
Usage #
Import it in your Dart code and use it with your objects like in the example below. You can see the generated code example if you like.
import 'dart:convert'; // You'll need this if you use `dynamic` fields
import 'package:dynamo_json/dynamo_json.dart';

part 'example.g.dart';

@DynamoJson()
class Person {
final String firstName, lastName;
final DateTime? dateOfBirth;
final List<Person> relatives;
final dynamic stateBucket;

// Explicitly ignore because it's explicitly set.
// In general, `late` fields are supported.
@DynamoIgnore()
late final bool hasState;

Person({
required this.firstName,
required this.lastName,
this.dateOfBirth,
this.relatives = const [],
this.stateBucket,
}) {
hasState = stateBucket != null;
}

factory Person.fromDynamoJson(Map<String, dynamic> json) =>
_$PersonFromDynamoJson(json);

Map<String, dynamic> toDynamoJson() => _$PersonToDynamoJson(this);
}
copied to clipboard
@DynamoJson() #
Can only be used on classes to indicate the need for (de)serialization support.
@DynamoIgnore() #
Can only be used on fields to indicate they should not be considered by the generated code.
Reference #
For details, see the documentation.

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.