CopyPastor

Detecting plagiarism made easy.

Score: 0.8319638035763269; Reported for: String similarity Open both answers

Possible Plagiarism

Reposted on 2025-08-28
by Thang Duong

Original Post

Original - Posted on 2025-08-28
by Thang Duong



            
Present in both answers; Present only in the new answer; Present only in the old answer;

Use pub.dev/packages/json_factory_generator
with JsonFactory auto gen
``` import 'package:example/generated/json_factory.dart'; import 'package:json_annotation/json_annotation.dart';
part 'base_response.g.dart';
/// Generic API response wrapper with JsonSerializable @JsonSerializable(genericArgumentFactories: true) class BaseResponse<T> { final bool success; final String message; @DataConverter() final T? data; final int? code;
BaseResponse({ required this.success, required this.message, this.data, this.code, });
/// Generated fromJson with generic type support factory BaseResponse.fromJson( Map<String, dynamic> json, T Function(Object? json) fromJsonT, ) => _$BaseResponseFromJson(json, fromJsonT);
/// Generated toJson with generic type support Map<String, dynamic> toJson(Object? Function(T value) toJsonT) => _$BaseResponseToJson(this, toJsonT);
@override String toString() { return 'BaseResponse(success: $success, message: $message, data: $data, code: $code)'; } }
class DataConverter<T> implements JsonConverter<T?, Object?> { const DataConverter();
@override T? fromJson(Object? json) { return JsonFactory.fromJson(json); }
@override Object? toJson(T? object) { return object; } } ```
Use <https://pub.dev/packages/json_factory_generator>
And run: `dart run build_runner build`
``` import 'package:example/generated/json_factory.dart'; import 'package:json_annotation/json_annotation.dart';
part 'base_response.g.dart';
/// Generic API response wrapper with JsonSerializable @JsonSerializable(genericArgumentFactories: true) class BaseResponse<T> { final bool success; final String message; @DataConverter() final T? data; final int? code;
BaseResponse({ required this.success, required this.message, this.data, this.code, });
/// Generated fromJson with generic type support factory BaseResponse.fromJson( Map<String, dynamic> json, T Function(Object? json) fromJsonT, ) => _$BaseResponseFromJson(json, fromJsonT);
/// Generated toJson with generic type support Map<String, dynamic> toJson(Object? Function(T value) toJsonT) => _$BaseResponseToJson(this, toJsonT);
@override String toString() { return 'BaseResponse(success: $success, message: $message, data: $data, code: $code)'; } }
class DataConverter<T> implements JsonConverter<T?, Object?> { const DataConverter();
@override T? fromJson(Object? json) { return JsonFactory.fromJson(json); }
@override Object? toJson(T? object) { return object; } } ```

        
Present in both answers; Present only in the new answer; Present only in the old answer;