codelessly_json_serializable 7.0.0 copy "codelessly_json_serializable: ^7.0.0" to clipboard
codelessly_json_serializable: ^7.0.0 copied to clipboard

SDKDart
unlisted

Automatically generate code for converting to and from JSON by annotating Dart classes.

example/example.dart

// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:codelessly_json_annotation/codelessly_json_annotation.dart';

part 'example.g.dart';

@JsonSerializable()
class Person {
  /// The generated code assumes these values exist in JSON.
  final String firstName, lastName;

  /// The generated code below handles if the corresponding JSON value doesn't
  /// exist or is empty.
  final DateTime? dateOfBirth;

  Person({required this.firstName, required this.lastName, this.dateOfBirth});

  /// Connect the generated [_$PersonFromJson] function to the `fromJson`
  /// factory.
  factory Person.fromJson(Map<String, dynamic> json) => _$PersonFromJson(json);

  /// Connect the generated [_$PersonToJson] function to the `toJson` method.
  Map<String, dynamic> toJson() => _$PersonToJson(this);
}
0
likes
130
points
21
downloads

Publisher

verified publishercodelessly.com

Weekly Downloads

Automatically generate code for converting to and from JSON by annotating Dart classes.

Topics

#json #build-runner #json-serializable #codegen

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

analyzer, async, build, build_config, codelessly_json_annotation, collection, meta, path, pub_semver, pubspec_parse, source_gen, source_helper

More

Packages that depend on codelessly_json_serializable