Aqueduct 및 Dart: Future<List<T>>(T = ManagedObject)를 JSON으로 직렬화할 수 없습니다. (Aqueduct and Dart: Future<List<T>> (T = ManagedObject) can't be serialized to JSON)


문제 설명

Aqueduct 및 Dart: Future<List>(T = ManagedObject)를 JSON으로 직렬화할 수 없습니다. (Aqueduct and Dart: Future<List> (T = ManagedObject) can't be serialized to JSON)

Aqueduct와 Dart에 익숙해지기 위해 여기 자습서를 따르고 있었습니다. 파트 1의 코드는 제대로 작동했지만 메모리 내 영웅 목록에서 데이터베이스 사용으로 변환하면 작동이 중지되었습니다. 데이터베이스(Postgres)에 데이터가 있고 백엔드가 성공적으로 연결되어 DB에서 읽는 것을 확인했습니다. 그러나 ManagedObject를 직렬화할 수 없다는 오류가 발생했습니다. 이 튜토리얼에서는 직렬화에 대한 세부 정보를 언급하지 않습니다. 내 모델 클래스에 @JsonSerializable을 추가하려고 시도했지만 여전히 동일한 문제가 있었습니다. 그것은 모델 개체 자체가 아니라 API가 다음을 반환한다는 사실인 것 같습니다. Future> </코드>? 오류:

Converting object to an encodable object failed: Instance of 'Future<List<Hero>>' #0      _JsonStringifier.writeObject (dart:convert/json.dart:649:7)

튜토리얼에서는 ManagedObject를 확장하는 클래스가 기본적으로/자동으로 직렬화 가능하다고 제안하는 것 같습니다. 그 가정이 잘못된 것인가? Aqueduct 웹사이트에서 바로 사용할 수 있는 튜토리얼이 있다는 것이 이상하게 보입니다.


참조 솔루션

방법 1:

I was missing the await keyword on the database query which explains why the API call was returning a Future> instead of the actual List. Doh!

(by Michael BatchelderMichael Batchelder)

참조 문서

  1. Aqueduct and Dart: Future<List> (T = ManagedObject) can't be serialized to JSON (CC BY‑SA 2.5/3.0/4.0)

#dart #aqueduct #JSON






관련 질문

경고 대신 오류로 "@required" 주석 ("@required" annotation as error instead of warning)

Flutter ThemeData가 텍스트에서 작동하지 않습니다 (Flutter ThemeData is not working for the Text)

Aqueduct 및 Dart: Future<List<T>>(T = ManagedObject)를 JSON으로 직렬화할 수 없습니다. (Aqueduct and Dart: Future<List<T>> (T = ManagedObject) can't be serialized to JSON)

나는 세 개의 텍스트 필드가 있는데 그 중 처음 두 개 중에서 선택하고 세 번째 필드로 작업하고 싶습니다. (I have three text fields, want to choose between first two of them, & work with third one)

각 페이지에 대한 동적 높이로 Flutter Carousel Slider 만들기 (Create a Flutter Carousel Slider with dynamic heigth for each page)

SMS를 보낼 때 flutter url_launcher의 해시 기호 뒤에 메시지 본문이 사라집니다. (Message body disappear after hash symbol in flutter url_launcher when send a SMS)

미래 방법을 조롱하고 'Null'유형을 얻지 않는 방법은 플러터에서 'Future<>'유형의 하위 유형이 아닙니다. (How to mock a future method and not get type 'Null' is not a subtype of type 'Future<>' in flutter)

【NoSuchMethodError】audio_service가 initState에서 시작되지 않습니다 (【NoSuchMethodError】audio_service does not start in initState)

플러터에서 양식 변수를 얻는 방법 (How to get form variables in flutter)

다른 프로세스에서 사용 중이기 때문에 Pub에서 항목을 삭제하지 못했습니다. (Pub failed to delete entry because it was in use by another process)

RenderViewport는 RenderSliver 유형의 하위를 예상했지만 RenderErrorBox 유형의 하위를 수신했습니다. (A RenderViewport expected a child of type RenderSliver but received a child of type RenderErrorBox)

Flutter에서 이름을 확인하는 방법은 무엇입니까? (How to validate Name in flutter?)







코멘트