Skip to content

Commit

Permalink
chore: removed manual toJson and replace jsonSerializable with zAmpli…
Browse files Browse the repository at this point in the history
…fySerializable
  • Loading branch information
khatruong2009 committed Sep 15, 2023
1 parent 03a8455 commit 05391d8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 47 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import 'package:aws_common/aws_common.dart';
import 'package:amplify_core/amplify_core.dart';
import 'package:aws_logging_cloudwatch/aws_logging_cloudwatch.dart';
import 'package:json_annotation/json_annotation.dart';

part 'plugin_config.g.dart';

Expand Down Expand Up @@ -63,27 +62,8 @@ class LoggingConstraint with AWSDebuggable {
factory LoggingConstraint.fromJson(Map<String, dynamic> json) =>
_$LoggingConstraintFromJson(json);

// /// Converts an [LoggingConstraint] instance to a [Map].
// Map<String, dynamic> toJson() => _$LoggingConstraintToJson(this);

/// Converts an [LoggingConstraint] instance to a [Map].
Map<String, dynamic> toJson() {
final jsonMap = <String, dynamic>{
'defaultLogLevel':
defaultLogLevel.toString().split('.').last, // Convert enum to string
'categoryLogLevel': categoryLogLevel?.map(
(key, value) => MapEntry(key, value.toString().split('.').last),
),
};

if (userLogLevel != null) {
jsonMap['userLogLevel'] = userLogLevel!.map(
(key, value) => MapEntry(key, value.toJson()),
);
}

return jsonMap;
}
Map<String, dynamic> toJson() => _$LoggingConstraintToJson(this);

/// The default [LogLevel] for sending logs to CloudWatch.
final LogLevel defaultLogLevel;
Expand Down Expand Up @@ -112,18 +92,7 @@ class UserLogLevel {
_$UserLogLevelFromJson(json);

/// Converts a [UserLogLevel] instance to a [Map].
Map<String, dynamic> toJson() => {
'defaultLogLevel': defaultLogLevel
?.toString()
.split('.')
.last, // Convert enum to string
'categoryLogLevel': categoryLogLevel?.map(
(key, value) => MapEntry(
key,
value.toString().split('.').last,
), // Convert enum to string
),
};
Map<String, dynamic> toJson() => _$UserLogLevelToJson(this);

/// The default [LogLevel] for sending logs to CloudWatch.
final LogLevel? defaultLogLevel;
Expand Down

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

0 comments on commit 05391d8

Please sign in to comment.