Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…dart into add-json-converter-option
  • Loading branch information
rrousselGit committed Apr 27, 2022
2 parents 876faa7 + 0d836a4 commit 058bcab
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Expand Up @@ -8,4 +8,4 @@ updates:
directory: "/"
schedule:
# Check for updates to GitHub Actions weekly
interval: "weekly"
interval: "monthly"
2 changes: 2 additions & 0 deletions checked_yaml/pubspec.yaml
Expand Up @@ -24,3 +24,5 @@ dev_dependencies:
dependency_overrides:
json_annotation:
path: ../json_annotation
json_serializable:
path: ../json_serializable
4 changes: 4 additions & 0 deletions json_annotation/CHANGELOG.md
@@ -1,3 +1,7 @@
## 4.5.0

- Added `FieldRename.screamingSnake`.

## 4.4.0

- Added `JsonKey.readValue`.
Expand Down
6 changes: 5 additions & 1 deletion json_annotation/lib/src/json_serializable.dart
Expand Up @@ -23,7 +23,11 @@ enum FieldRename {
snake,

/// Encodes a field named `pascalCase` with a JSON key `PascalCase`.
pascal
pascal,

/// Encodes a field named `screamingSnakeCase` with a JSON key
/// `SCREAMING_SNAKE_CASE`
screamingSnake,
}

/// An annotation used to specify a class to generate code for.
Expand Down
1 change: 1 addition & 0 deletions json_annotation/lib/src/json_serializable.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion json_annotation/pubspec.yaml
@@ -1,5 +1,5 @@
name: json_annotation
version: 4.4.0
version: 4.5.0
description: >-
Classes and helper functions that support JSON code generation via the
`json_serializable` package.
Expand Down
5 changes: 5 additions & 0 deletions json_serializable/CHANGELOG.md
@@ -1,3 +1,8 @@
## 6.2.0

- Added support for the new `FieldRename.screamingSnake` field in
`package:json_annotation`.

## 6.1.6

- Allow latest `package:analyzer`.
Expand Down
16 changes: 8 additions & 8 deletions json_serializable/README.md
Expand Up @@ -199,14 +199,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.4.0/json_annotation/JsonConverter-class.html
[`JsonEnum`]: https://pub.dev/documentation/json_annotation/4.4.0/json_annotation/JsonEnum-class.html
[`JsonKey.fromJson`]: https://pub.dev/documentation/json_annotation/4.4.0/json_annotation/JsonKey/fromJson.html
[`JsonKey.toJson`]: https://pub.dev/documentation/json_annotation/4.4.0/json_annotation/JsonKey/toJson.html
[`JsonKey`]: https://pub.dev/documentation/json_annotation/4.4.0/json_annotation/JsonKey-class.html
[`JsonLiteral`]: https://pub.dev/documentation/json_annotation/4.4.0/json_annotation/JsonLiteral-class.html
[`JsonSerializable`]: https://pub.dev/documentation/json_annotation/4.4.0/json_annotation/JsonSerializable-class.html
[`JsonValue`]: https://pub.dev/documentation/json_annotation/4.4.0/json_annotation/JsonValue-class.html
[`JsonConverter`]: https://pub.dev/documentation/json_annotation/4.5.0/json_annotation/JsonConverter-class.html
[`JsonEnum`]: https://pub.dev/documentation/json_annotation/4.5.0/json_annotation/JsonEnum-class.html
[`JsonKey.fromJson`]: https://pub.dev/documentation/json_annotation/4.5.0/json_annotation/JsonKey/fromJson.html
[`JsonKey.toJson`]: https://pub.dev/documentation/json_annotation/4.5.0/json_annotation/JsonKey/toJson.html
[`JsonKey`]: https://pub.dev/documentation/json_annotation/4.5.0/json_annotation/JsonKey-class.html
[`JsonLiteral`]: https://pub.dev/documentation/json_annotation/4.5.0/json_annotation/JsonLiteral-class.html
[`JsonSerializable`]: https://pub.dev/documentation/json_annotation/4.5.0/json_annotation/JsonSerializable-class.html
[`JsonValue`]: https://pub.dev/documentation/json_annotation/4.5.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
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.4.0');
final requiredJsonAnnotationMinVersion = Version.parse('4.5.0');

Future<void> pubspecHasRightVersion(BuildStep buildStep) async {
final segments = buildStep.inputId.pathSegments;
Expand Down
2 changes: 2 additions & 0 deletions json_serializable/lib/src/utils.dart
Expand Up @@ -181,6 +181,8 @@ String encodedFieldName(
return declaredName;
case FieldRename.snake:
return declaredName.snake;
case FieldRename.screamingSnake:
return declaredName.snake.toUpperCase();
case FieldRename.kebab:
return declaredName.kebab;
case FieldRename.pascal:
Expand Down
7 changes: 3 additions & 4 deletions json_serializable/pubspec.yaml
@@ -1,5 +1,5 @@
name: json_serializable
version: 6.1.6
version: 6.2.0
description: >-
Automatically generate code for converting to and from JSON by annotating
Dart classes.
Expand All @@ -16,7 +16,7 @@ dependencies:

# Use a tight version constraint to ensure that a constraint on
# `json_annotation` properly constrains all features it provides.
json_annotation: '>=4.4.0 <4.5.0'
json_annotation: '>=4.5.0 <4.6.0'
meta: ^1.3.0
path: ^1.8.0
pub_semver: ^2.0.0
Expand All @@ -37,7 +37,6 @@ dev_dependencies:
test_process: ^2.0.0
yaml: ^3.0.0


dependency_overrides:
json_annotation:
path: ../json_annotation
path: ../json_annotation
2 changes: 1 addition & 1 deletion json_serializable/test/config_test.dart
Expand Up @@ -120,7 +120,7 @@ void main() {
case 'field_rename':
lastLine =
'`42` is not one of the supported values: none, kebab, snake, '
'pascal';
'pascal, screamingSnake';
break;
case 'constructor':
lastLine = "type 'int' is not a subtype of type 'String?' in type "
Expand Down
1 change: 1 addition & 0 deletions json_serializable/test/json_serializable_test.dart
Expand Up @@ -58,6 +58,7 @@ const _expectedAnnotatedTests = {
'FieldNamerKebab',
'FieldNamerNone',
'FieldNamerPascal',
'FieldNamerScreamingSnake',
'FieldNamerSnake',
'FieldWithFromJsonCtorAndTypeParams',
'FinalFields',
Expand Down
16 changes: 16 additions & 0 deletions json_serializable/test/src/field_namer_input.dart
Expand Up @@ -59,3 +59,19 @@ class FieldNamerSnake {
@JsonKey(name: 'NAME_OVERRIDE')
late String nameOverride;
}

@ShouldGenerate(r'''
Map<String, dynamic> _$FieldNamerScreamingSnakeToJson(
FieldNamerScreamingSnake instance) =>
<String, dynamic>{
'THE_FIELD': instance.theField,
'nameOverride': instance.nameOverride,
};
''')
@JsonSerializable(fieldRename: FieldRename.screamingSnake, createFactory: false)
class FieldNamerScreamingSnake {
late String theField;

@JsonKey(name: 'nameOverride')
late String nameOverride;
}

0 comments on commit 058bcab

Please sign in to comment.