Open Albert221 opened 1 year ago
Looks like this is the same issue I'm facing here: https://github.com/rrousselGit/freezed/issues/766#issuecomment-1811414548
Sadly, I have the same issue here as well.
Same issue on my end :
import 'package:freezed_annotation/freezed_annotation.dart';
part 'attempt_result.freezed.dart';
part 'attempt_result.g.dart';
@freezed
class AttemptResult with _$AttemptResult {
factory AttemptResult({
required bool isCorrect,
required AttemptResultProperty<String> name,
}) = _AttemptResult;
factory AttemptResult.fromJson(Map<String, dynamic> json) =>
_$AttemptResultFromJson(json);
}
@Freezed(genericArgumentFactories: true)
class AttemptResultProperty<T> with _$AttemptResultProperty<T> {
factory AttemptResultProperty({
required String state,
required T value,
}) = _AttemptResultProperty<T>;
factory AttemptResultProperty.fromJson(
Map<String, dynamic> json, T Function(Object?) fromJsonT) =>
_$AttemptResultPropertyFromJson(json, fromJsonT);
}
[SEVERE] json_serializable on lib/core/models/attempt_result.dart:
RangeError (index): Invalid value: Only valid value is 0: -1
dart:core _Array.[]
package:json_serializable/src/type_helpers/json_helper.dart 161:39 _helperParams
package:json_serializable/src/type_helpers/json_helper.dart 51:9 JsonHelper.serialize
package:json_serializable/src/type_helper_ctx.dart 56:31 TypeHelperCtx.serialize.<fn>
dart:core Iterable.firstWhere
package:json_serializable/src/type_helper_ctx.dart 88:46 TypeHelperCtx._run
package:json_serializable/src/type_helper_ctx.dart 53:64 TypeHelperCtx.serialize
package:json_serializable/src/encoder_helper.dart 206:12 EncodeHelper._serializeField
package:json_serializable/src/encoder_helper.dart 134:42 EncodeHelper._writeToJsonSimple.<fn>
dart:core StringBuffer.writeAll
package:json_serializable/src/encoder_helper.dart 131:9 EncodeHelper._writeToJsonSimple
package:json_serializable/src/encoder_helper.dart 107:7 EncodeHelper.createToJson
dart:_internal WhereIterator.moveNext
package:json_serializable/src/json_part_builder.dart 64:27 _UnifiedGenerator.generate
package:source_gen/src/builder.dart 342:23 _generate
dart:async Stream.toList.<fn>
package:source_gen/src/builder.dart 107:9 _Builder._generateForLibrary
package:source_gen/src/builder.dart 99:5 _Builder.build
Same issue here
import 'package:freezed_annotation/freezed_annotation.dart';
part 'base_response.freezed.dart';
part 'base_response.g.dart';
@Freezed(genericArgumentFactories: true)
class SBaseResponse<T, E> with _$SBaseResponse<T, E> {
const factory SBaseResponse({
required SResponseStatus<E> responseStatus,
required T results,
}) = _SBaseResponse;
const SBaseResponse._();
factory SBaseResponse.fromJson(
Map<String, dynamic> json,
T Function(Object?) fromJsonT,
E Function(Object?) fromJsonE,
) =>
_$SBaseResponseFromJson(json, fromJsonT, fromJsonE);
}
@Freezed(genericArgumentFactories: true)
class SResponseStatus<E> with _$SResponseStatus<E> {
const factory SResponseStatus({
String? errorCode,
String? message,
E? errors,
}) = _SResponseStatus;
const SResponseStatus._();
factory SResponseStatus.fromJson(
Map<String, Object?> json,
E Function(Object? json) fromJsonE,
) =>
_$SResponseStatusFromJson(json, fromJsonE);
}
[SEVERE] json_serializable on lib/src/models/base_response.dart:
RangeError (index): Invalid value: Only valid value is 0: -1
dart:core _Array.[]
package:json_serializable/src/type_helpers/json_helper.dart 161:39 _helperParams
package:json_serializable/src/type_helpers/json_helper.dart 51:9 JsonHelper.serialize
package:json_serializable/src/type_helper_ctx.dart 56:31 TypeHelperCtx.serialize.<fn>
dart:core Iterable.firstWhere
package:json_serializable/src/type_helper_ctx.dart 88:46 TypeHelperCtx._run
package:json_serializable/src/type_helper_ctx.dart 53:64 TypeHelperCtx.serialize
package:json_serializable/src/encoder_helper.dart 206:12 EncodeHelper._serializeField
package:json_serializable/src/encoder_helper.dart 134:42 EncodeHelper._writeToJsonSimple.<fn>
dart:core StringBuffer.writeAll
package:json_serializable/src/encoder_helper.dart 131:9 EncodeHelper._writeToJsonSimple
package:json_serializable/src/encoder_helper.dart 107:7 EncodeHelper.createToJson
dart:_internal WhereIterator.moveNext
package:json_serializable/src/json_part_builder.dart 64:27 _UnifiedGenerator.generate
package:source_gen/src/builder.dart 342:23 _generate
dart:async Stream.toList.<fn>
package:source_gen/src/builder.dart 107:9 _Builder._generateForLibrary
package:source_gen/src/builder.dart 99:5 _Builder.build
Same issue here. Did you find any solution?
import 'package:freezed_annotation/freezed_annotation.dart';
part 'api_response.freezed.dart';
part 'api_response.g.dart';
@Freezed(genericArgumentFactories: true)
class APIResponse<T> with _$APIResponse<T> {
factory APIResponse.fromJson(
Map<String, dynamic> json, T Function(Object? json) fromJsonT) =>
_$APIResponseFromJson<T>(json, fromJsonT);
@JsonSerializable(explicitToJson: true, genericArgumentFactories: true)
const factory APIResponse({
required bool success,
required APIResult<T> result,
String? message,
}) = _APIResponse;
}
@Freezed(genericArgumentFactories: true)
class APIResult<R> with _$APIResult<R> {
factory APIResult.fromJson(
Map<String, dynamic> json, R Function(Object? json) fromJsonR) =>
_$APIResultFromJson<R>(json, fromJsonR);
@JsonSerializable(explicitToJson: true, genericArgumentFactories: true)
const factory APIResult({
R? data,
}) = _APIResult;
}
RangeError (length): Invalid value: Only valid value is 0: -1
dart:core _Array.[]
package:json_serializable/src/type_helpers/json_helper.dart 161:39 _helperParams
package:json_serializable/src/type_helpers/json_helper.dart 51:9 JsonHelper.serialize
package:json_serializable/src/type_helper_ctx.dart 56:31 TypeHelperCtx.serialize.<fn>
dart:core Iterable.firstWhere
package:json_serializable/src/type_helper_ctx.dart 88:46 TypeHelperCtx._run
package:json_serializable/src/type_helper_ctx.dart 53:64 TypeHelperCtx.serialize
package:json_serializable/src/encoder_helper.dart 206:12 EncodeHelper._serializeField
package:json_serializable/src/encoder_helper.dart 134:42 EncodeHelper._writeToJsonSimple.<fn>
dart:core StringBuffer.writeAll
package:json_serializable/src/encoder_helper.dart 131:9 EncodeHelper._writeToJsonSimple
package:json_serializable/src/encoder_helper.dart 107:7 EncodeHelper.createToJson
dart:_internal WhereIterator.moveNext
package:json_serializable/src/json_part_builder.dart 64:27 _UnifiedGenerator.generate
package:source_gen/src/builder.dart 342:23 _generate
dart:async Stream.toList.<fn>
package:source_gen/src/builder.dart 107:9 _Builder._generateForLibrary
package:source_gen/src/builder.dart 99:5 _Builder.build
Describe the bug A clear and concise description of what the bug is.
Error
Expected behavior Proper
fromJson
createdProbably related to #882.