|
| 1 | +// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
| 2 | +// for details. All rights reserved. Use of this source code is governed by a |
| 3 | +// BSD-style license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +import 'package:source_gen/source_gen.dart'; |
| 6 | + |
| 7 | +import 'json_literal_generator.dart'; |
| 8 | +import 'json_serializable_generator.dart'; |
| 9 | + |
| 10 | +/// Returns a [PartBuilder] for use within a `package:build_runner` |
| 11 | +/// `BuildAction`. |
| 12 | +/// |
| 13 | +/// [header] is used to specify the content at the top of each generated file. |
| 14 | +/// If `null`, the content of [defaultFileHeader] is used. |
| 15 | +/// If [header] is an empty `String` no header is added. |
| 16 | +/// |
| 17 | +/// If [useWrappers] is `true`, wrappers are used to minimize the number of |
| 18 | +/// [Map] and [List] instances created during serialization. This will |
| 19 | +/// increase the code size, but it may improve runtime performance, especially |
| 20 | +/// for large object graphs. |
| 21 | +/// |
| 22 | +/// Usage: |
| 23 | +/// |
| 24 | +/// ```dart |
| 25 | +/// new BuildAction( |
| 26 | +/// jsonPartBuilder(), |
| 27 | +/// 'my_package', |
| 28 | +/// inputs: const ['lib/*.dart'] |
| 29 | +/// ) |
| 30 | +/// ``` |
| 31 | +/// |
| 32 | +/// See the [example] to understand how to configure your project for |
| 33 | +/// `json_serializable`. |
| 34 | +/// |
| 35 | +/// [example]: https://github.com/dart-lang/json_serializable/tree/master/example |
| 36 | +PartBuilder jsonPartBuilder({String header, bool useWrappers: false}) { |
| 37 | + useWrappers ??= false; |
| 38 | + return new PartBuilder([ |
| 39 | + new JsonSerializableGenerator(useWrappers: useWrappers), |
| 40 | + const JsonLiteralGenerator() |
| 41 | + ], header: header); |
| 42 | +} |
0 commit comments