OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.2k stars 6.43k forks source link

Error deserializing #15177

Open knightsforce opened 1 year ago

knightsforce commented 1 year ago

When receiving JSON: [ { "id": 1, "name": "Test", "schedule": { "slots": [ [], [], [], [], [], [], [ { "time_from": "10:30:00", "time_to": "15:45:00" } ] ] } } ]

I get an error after the response: DioError [unknown]: null I/flutter (19668): │ Error: Deserializing '[{id: 2, name: Test, email: test@gmail.com...' to 'BuiltList' failed due to: Deserializing '[id, 2, name, Test, email, test@gmail.com...' to 'OverviewPlace' failed due to: Deserializing '[slots, [[], [{time_from: 07:00:00, time_to: 14:00:00}, {time_from: 15:00:00,...' to 'Schedule?' failed due to: Deserializing '[[], [{time_from: 07:00:00, time_to: 14:00:00}, {time_from: 15:00:00, time_to...' to 'BuiltList<BuiltList>' failed due to: Deserializing '[]' to 'BuiltList' failed due to: Bad state: No builder factory for BuiltList. Fix by adding one, see SerializersBuilder.addBuilderFactory.

It was solved by adding the code to the serializers.dart file: ..addBuilderFactory( const FullType(BuiltList, [FullType(TimeSlot)]), () => ListBuilder(), )

ahmednfwela commented 1 year ago

@jaumard (2018/09) @josh-burton (2019/12) @amondnet (2019/12) @sbu-WBT (2020/12) @kuhnroyal (2020/12) @agilob (2020/12) @ahmednfwela (2021/08)

kuhnroyal commented 1 year ago

Serializing lists of lists is tricky with built_value, but if you can provide a sample spec, we can probably fix this.

hellozyemlya commented 2 months ago

openapi (1).json Here is an example of openapi spec that producing same error:

Error: Deserializing to 'BuiltList<TorrentModel>' failed due to: Deserializing to 'TorrentModel' failed due to: Deserializing to 'BuiltMap<String, BuiltList<FilesMetaInner>>' failed due to: Deserializing to 'BuiltList<FilesMetaInner>' failed due to: Bad state: No builder factory for BuiltList<FilesMetaInner>. Fix by adding one, see SerializersBuilder.addBuilderFactory.

adding this to serializers fixes it:

      ..addBuilderFactory(
          const FullType(BuiltList, const [const FullType(FilesMetaInner)]),
          () => new ListBuilder<FilesMetaInner>())