Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
308 changes: 167 additions & 141 deletions .github/workflows/dart.yml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion _test_yaml/mono_pkg.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# See https://github.com/google/mono_repo.dart for details on this file
sdk:
- 2.14.0
- pubspec
- dev

stages:
Expand Down
4 changes: 3 additions & 1 deletion _test_yaml/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: _test_yaml
publish_to: none

environment:
sdk: '>=2.14.0 <3.0.0'
sdk: '>=2.17.0 <3.0.0'

dev_dependencies:
_json_serial_shared_test:
Expand All @@ -12,6 +12,8 @@ dev_dependencies:
checked_yaml: any
json_annotation: ^4.4.0
json_serializable: any
lints: ^2.0.0
path: ^1.8.2
test: ^1.6.0
yaml: ^3.0.0

Expand Down
80 changes: 3 additions & 77 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,123 +1,49 @@
include: package:lints/recommended.yaml

analyzer:
language:
strict-casts: true

linter:
rules:
- always_declare_return_types
- always_require_non_null_named_parameters
- annotate_overrides
- avoid_catching_errors
- avoid_dynamic_calls
- avoid_empty_else
- avoid_function_literals_in_foreach_calls
- avoid_init_to_null
- avoid_null_checks_in_equality_operators
- avoid_private_typedef_functions
- avoid_redundant_argument_values
- avoid_relative_lib_imports
- avoid_renaming_method_parameters
- avoid_return_types_on_setters
- avoid_returning_null
- avoid_returning_null_for_void
- avoid_shadowing_type_parameters
- avoid_single_cascade_in_expression_statements
- avoid_types_as_parameter_names
- avoid_unused_constructor_parameters
- avoid_void_async
- await_only_futures
- camel_case_extensions
- camel_case_types
- cancel_subscriptions
- cascade_invocations
- comment_references
- constant_identifier_names
- control_flow_in_finally
- curly_braces_in_flow_control_structures
- directives_ordering
- empty_catches
- empty_constructor_bodies
- empty_statements
- exhaustive_cases
- file_names
- hash_and_equals
- implementation_imports
- invariant_booleans
- iterable_contains_unrelated_type
- join_return_with_assignment
- library_names
- library_prefixes
- lines_longer_than_80_chars
- list_remove_unrelated_type
- literal_only_boolean_expressions
- missing_whitespace_between_adjacent_strings
- no_duplicate_case_values
- no_runtimeType_toString
- non_constant_identifier_names
- null_closures
- omit_local_variable_types
- only_throw_errors
- overridden_fields
- package_api_docs
- package_names
- package_prefixed_library_names
- prefer_adjacent_string_concatenation
- prefer_asserts_in_initializer_lists
- prefer_collection_literals
- prefer_conditional_assignment
- prefer_const_constructors
- prefer_const_declarations
- prefer_contains
- prefer_equal_for_default_values
- prefer_expression_function_bodies
- prefer_final_fields
- prefer_final_locals
- prefer_for_elements_to_map_fromIterable
- prefer_function_declarations_over_variables
- prefer_generic_function_type_aliases
- prefer_if_null_operators
- prefer_initializing_formals
- prefer_inlined_adds
- prefer_interpolation_to_compose_strings
- prefer_is_empty
- prefer_is_not_empty
- prefer_is_not_operator
- prefer_iterable_whereType
- prefer_null_aware_operators
- prefer_relative_imports
- prefer_single_quotes
- prefer_spread_collections
- prefer_typing_uninitialized_variables
- prefer_void_to_null
- provide_deprecation_message
- recursive_getters
- slash_for_doc_comments
- sort_child_properties_last
- sort_pub_dependencies
- test_types_in_equals
- throw_in_finally
- type_annotate_public_apis
- type_init_formals
- unawaited_futures
- unnecessary_brace_in_string_interps
- unnecessary_const
- unnecessary_getters_setters
- unnecessary_lambdas
- unnecessary_new
- unnecessary_null_aware_assignments
- unnecessary_null_in_if_null_operators
- unnecessary_overrides
- unnecessary_parenthesis
- unnecessary_statements
- unnecessary_string_escapes
- unnecessary_string_interpolations
- unnecessary_this
- unrelated_type_equality_checks
- unsafe_html
- use_full_hex_values_for_flutter_colors
- use_function_type_syntax_for_parameters
- use_is_even_rather_than_modulo
- use_rethrow_when_possible
- use_string_buffers
- valid_regexps
- void_checks
- use_super_parameters
2 changes: 1 addition & 1 deletion checked_yaml/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## 2.0.2-dev

- Require `json_annotation` `^4.3.0`
- Require Dart SDK `>=2.14`
- Require Dart SDK `>=2.17`

## 2.0.1

Expand Down
2 changes: 1 addition & 1 deletion checked_yaml/mono_pkg.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# See https://github.com/google/mono_repo.dart for details on this file
sdk:
- 2.14.0
- pubspec
- dev

stages:
Expand Down
3 changes: 2 additions & 1 deletion checked_yaml/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description: >-
package:json_serializable and package:yaml.
repository: https://github.com/google/json_serializable.dart/tree/master/checked_yaml
environment:
sdk: '>=2.14.0 <3.0.0'
sdk: '>=2.17.0 <3.0.0'

dependencies:
json_annotation: ^4.3.0
Expand All @@ -17,6 +17,7 @@ dev_dependencies:
build_runner: ^2.0.0
build_verify: ^3.0.0
json_serializable: ^6.0.0
lints: ^2.0.0
path: ^1.0.0
test: ^1.16.0
test_process: ^2.0.0
Expand Down
2 changes: 1 addition & 1 deletion example/mono_pkg.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# See https://github.com/google/mono_repo.dart for details on this file
sdk:
- 2.14.0
- pubspec
- dev

stages:
Expand Down
10 changes: 7 additions & 3 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: example
publish_to: none

environment:
sdk: '>=2.14.0 <3.0.0'
sdk: '>=2.17.0 <3.0.0'

dependencies:
json_annotation: ^4.4.0
Expand All @@ -18,7 +18,11 @@ dev_dependencies:

json_serializable: ^6.0.0

# Used by tests. Not required to use `json_serializable`.
# Not required to use `json_serializable`.
lints: ^2.0.0
path: ^1.8.0
# Used by tests. Not required to use `json_serializable`.
test: ^1.16.0

dependency_overrides:
json_serializable:
path: ../json_serializable
7 changes: 7 additions & 0 deletions json_annotation/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 4.7.0

- Added `JsonEnum.valueField` which allows specifying a field in an
"enhanced enum" to use for serialization instead of specifying each value
individually with `JsonValue`.
- Require Dart SDK 2.17

## 4.6.0

- Added `JsonSerializable(createFieldMap: true)`.
Expand Down
10 changes: 4 additions & 6 deletions json_annotation/lib/src/checked_helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

import 'allowed_keys_helpers.dart';

typedef _CastFunction<R> = R Function(Object?);

/// Helper function used in generated code when
/// `JsonSerializableGenerator.checked` is `true`.
///
Expand All @@ -16,24 +14,24 @@ T $checkedCreate<T>(
T Function(
S Function<S>(
String,
_CastFunction<S>, {
S Function(Object?), {
Object? Function(Map, String)? readValue,
}),
)
constructor, {
Map<String, String> fieldKeyMap = const {},
}) {
Q _checkedConvert<Q>(
Q checkedConvert<Q>(
String key,
_CastFunction<Q> convertFunction, {
Q Function(Object?) convertFunction, {
Object? Function(Map, String)? readValue,
}) =>
$checkedConvert<Q>(map, key, convertFunction, readValue: readValue);

return $checkedNew(
className,
map,
() => constructor(_checkedConvert),
() => constructor(checkedConvert),
fieldKeyMap: fieldKeyMap,
);
}
Expand Down
4 changes: 2 additions & 2 deletions json_annotation/lib/src/json_converter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/// [JsonConverter]s can be placed either on the class:
///
/// ```dart
/// class MyConverter extends JsonConverter<Value, JSON> {
/// class MyJsonConverter extends JsonConverter<Value, JSON> {
/// // TODO
/// }
///
Expand All @@ -36,7 +36,7 @@
/// Or finally, passed to the annotation:
///
///```dart
/// @JsonSerializable(converters: [MyConverter()])
/// @JsonSerializable(converters: [MyJsonConverter()])
/// class Example {}
/// ```
abstract class JsonConverter<T, S> {
Expand Down
8 changes: 8 additions & 0 deletions json_annotation/lib/src/json_enum.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class JsonEnum {
const JsonEnum({
this.alwaysCreate = false,
this.fieldRename = FieldRename.none,
this.valueField,
});

/// If `true`, `_$[enum name]EnumMap` is generated for in library containing
Expand All @@ -34,4 +35,11 @@ class JsonEnum {
/// Note: the value for [JsonValue.value] takes precedence over this option
/// for entries annotated with [JsonValue].
final FieldRename fieldRename;

/// Specifies the field within an "enhanced enum" to use as the value
/// to use for serialization.
///
/// If an individual `enum` element is annotated with `@JsonValue`
/// that value still takes precedence.
final String? valueField;
}
2 changes: 1 addition & 1 deletion json_annotation/mono_pkg.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# See https://github.com/google/mono_repo.dart for details on this file
sdk:
- 2.14.0
- pubspec
- dev

stages:
Expand Down
7 changes: 4 additions & 3 deletions json_annotation/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
name: json_annotation
version: 4.6.0
version: 4.7.0
description: >-
Classes and helper functions that support JSON code generation via the
`json_serializable` package.
repository: https://github.com/google/json_serializable.dart/tree/master/json_annotation

environment:
sdk: '>=2.14.0 <3.0.0'
sdk: '>=2.17.0 <3.0.0'

dependencies:
meta: ^1.4.0

dev_dependencies:
lints: ^2.0.0
# When changing JsonSerializable class.
# dev_dependencies:
# build_runner: ^2.0.0
# json_serializable: any
12 changes: 12 additions & 0 deletions json_serializable/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## 6.4.0

- Add support for `JsonEnum.valueField` which allows specifying a field in an
"enhanced enum" to use for serialization instead of specifying each value
individually with `JsonValue
- Require `json_annotation: '>=4.7.0 <4.8.0'`

## 6.3.2

- Require `analyzer: '>=4.6.0 <6.0.0'`
- Require `sdk: '>=2.17.0 <3.0.0'`

## 6.3.1

- Fixed support for `Duration` fields with default values.
Expand Down
16 changes: 8 additions & 8 deletions json_serializable/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,14 @@ targets:
[`Enum`]: https://api.dart.dev/stable/dart-core/Enum-class.html
[`int`]: https://api.dart.dev/stable/dart-core/int-class.html
[`Iterable`]: https://api.dart.dev/stable/dart-core/Iterable-class.html
[`JsonConverter`]: https://pub.dev/documentation/json_annotation/4.6.0/json_annotation/JsonConverter-class.html
[`JsonEnum`]: https://pub.dev/documentation/json_annotation/4.6.0/json_annotation/JsonEnum-class.html
[`JsonKey.fromJson`]: https://pub.dev/documentation/json_annotation/4.6.0/json_annotation/JsonKey/fromJson.html
[`JsonKey.toJson`]: https://pub.dev/documentation/json_annotation/4.6.0/json_annotation/JsonKey/toJson.html
[`JsonKey`]: https://pub.dev/documentation/json_annotation/4.6.0/json_annotation/JsonKey-class.html
[`JsonLiteral`]: https://pub.dev/documentation/json_annotation/4.6.0/json_annotation/JsonLiteral-class.html
[`JsonSerializable`]: https://pub.dev/documentation/json_annotation/4.6.0/json_annotation/JsonSerializable-class.html
[`JsonValue`]: https://pub.dev/documentation/json_annotation/4.6.0/json_annotation/JsonValue-class.html
[`JsonConverter`]: https://pub.dev/documentation/json_annotation/4.7.0/json_annotation/JsonConverter-class.html
[`JsonEnum`]: https://pub.dev/documentation/json_annotation/4.7.0/json_annotation/JsonEnum-class.html
[`JsonKey.fromJson`]: https://pub.dev/documentation/json_annotation/4.7.0/json_annotation/JsonKey/fromJson.html
[`JsonKey.toJson`]: https://pub.dev/documentation/json_annotation/4.7.0/json_annotation/JsonKey/toJson.html
[`JsonKey`]: https://pub.dev/documentation/json_annotation/4.7.0/json_annotation/JsonKey-class.html
[`JsonLiteral`]: https://pub.dev/documentation/json_annotation/4.7.0/json_annotation/JsonLiteral-class.html
[`JsonSerializable`]: https://pub.dev/documentation/json_annotation/4.7.0/json_annotation/JsonSerializable-class.html
[`JsonValue`]: https://pub.dev/documentation/json_annotation/4.7.0/json_annotation/JsonValue-class.html
[`List`]: https://api.dart.dev/stable/dart-core/List-class.html
[`Map`]: https://api.dart.dev/stable/dart-core/Map-class.html
[`num`]: https://api.dart.dev/stable/dart-core/num-class.html
Expand Down
2 changes: 1 addition & 1 deletion json_serializable/lib/src/check_dependencies.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'package:pubspec_parse/pubspec_parse.dart';

const _productionDirectories = {'lib', 'bin'};
const _annotationPkgName = 'json_annotation';
final requiredJsonAnnotationMinVersion = Version.parse('4.6.0');
final requiredJsonAnnotationMinVersion = Version.parse('4.7.0');

Future<void> pubspecHasRightVersion(BuildStep buildStep) async {
final segments = buildStep.inputId.pathSegments;
Expand Down
3 changes: 1 addition & 2 deletions json_serializable/lib/src/decode_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,7 @@ _ConstructorData _writeConstructorInvocation(

for (final arg in ctor.parameters) {
if (!availableConstructorParameters.contains(arg.name)) {
// ignore: deprecated_member_use
if (arg.isNotOptional) {
if (arg.isRequired) {
var msg = 'Cannot populate the required constructor '
'argument: ${arg.name}.';

Expand Down
Loading