import 'dart:convert'; // Mocking the behavior of the DTOs class TranslationDTO { String? language; String? value; TranslationDTO({this.language, this.value}); Map toJson() => {'language': language, 'value': value}; static TranslationDTO fromJson(Map json) => TranslationDTO(language: json['language'], value: json['value']); } class EventAddressDTOGeometry { String? type; Object? coordinates; EventAddressDTOGeometry({this.type, this.coordinates}); Map toJson() => {'type': type, 'coordinates': coordinates}; } class GuidedStepDTO { List? title; EventAddressDTOGeometry? geometry; GuidedStepDTO({this.title, this.geometry}); Map toJson() { final json = {}; if (this.title != null) { json['title'] = this.title!.map((v) => v.toJson()).toList(); } if (this.geometry != null) { json['geometry'] = this.geometry; // The reported bug: no .toJson() call } return json; } static GuidedStepDTO fromJson(dynamic value) { if (value is Map) { final json = value.cast(); return GuidedStepDTO( title: json['title'] != null ? (json['title'] as List) .map((i) => TranslationDTO.fromJson(i)) .toList() : null, geometry: json['geometry'] is Map ? EventAddressDTOGeometry( type: json['geometry']['type'], coordinates: json['geometry']['coordinates'], ) : (json['geometry'] is EventAddressDTOGeometry ? json['geometry'] : null), ); } return GuidedStepDTO(); } } void main() { var geo = EventAddressDTOGeometry(type: 'Point', coordinates: [1.0, 2.0]); var step = GuidedStepDTO( title: [TranslationDTO(language: 'FR', value: 'Test')], geometry: geo, ); print('Original geometry: ${step.geometry.runtimeType}'); var jsonMap = step.toJson(); print('Value in JSON map for geometry: ${jsonMap['geometry'].runtimeType}'); // This is what I do in showNewOrUpdateGuidedStep.dart var clonedStep = GuidedStepDTO.fromJson(jsonMap); print('Cloned geometry: ${clonedStep.geometry.runtimeType}'); // What happens if we actually JSON encode/decode? var encoded = jsonEncode(jsonMap); var decoded = jsonDecode(encoded); print('Decoded value for geometry: ${decoded['geometry'].runtimeType}'); var clonedStepFromJSON = GuidedStepDTO.fromJson(decoded); print( 'Cloned from actual JSON geometry: ${clonedStepFromJSON.geometry.runtimeType}'); }