nested json에 대한 처리 및 테스트는 어떻게 해야 할까요? ㅠ
529
작성한 질문수 10
강의에서 가르쳐주신 방법데로 개인플젝에 테스트 코드를 만들어서 사용하고 있는데요..
설계한 모델은
community, 그리고 이 안에 communitySetting을 담당하는 모델 2개를 만들어두었고 아래와 같이 freezed를 이용해서 구현을 해두었습니다.
Community model
(community setting 모델을 포함하는..)
@freezed
class Community with _$Community {
@JsonSerializable(fieldRename: FieldRename.snake, explicitToJson: true)
const factory Community({
int? id,
required String image,
required String name,
required String introduction,
required int publicStatus,
required String type,
required String detailType,
int? rank,
String? zipcode,
String? address,
required int approveRequiredStatus,
required String signupIntroduction,
required CommunitySetting settingJson
}) = _Community;
factory Community.fromJson(Map<String, dynamic> json) =>
_$CommunityFromJson(json);
}
CommunitySetting 모델
@freezed
class CommunitySetting with _$CommunitySetting {
@JsonSerializable(fieldRename: FieldRename.snake, explicitToJson: true)
const factory CommunitySetting({
required String configName,
required String fillPhone,
required String fillGender,
required String fillBirthDate,
required String fillActivityArea,
required String fillIntroduction,
required String fillMotivationToJoin,
}) = _CommunitySetting;
factory CommunitySetting.fromJson(Map<String, dynamic> json) =>
_$CommunitySettingFromJson(json);
}
그리고 test 코드에서는 fakeJson을 아래와 같이 nested json 있는 형태로 구성하고 테스트를 돌렸는데요
Nested Json은 setting_json 필드 입니다.
String fakeJsonOne = """
{
"id": 1,
"image": "https://www.google.com/url?sa=i&url=https%3A%2F%2Fwww.facebook.com%2Fgroups%2F623067261102382%2F&psig=AOvVaw3ok-tVpjly7PZseHURwtWJ&ust=1647397226257000&source=images&cd=vfe&ved=0CAsQjRxqFwoTCIjvr4qHx_YCFQAAAAAdAAAAABAD",
"name": "우리동네 커뮤니티",
"introduction": "우리동네 오신걸 환영합니다.",
"public_status": 1,
"type": "OFFICIAL",
"detail_type": "GNRL",
"ranking": null,
"zipcode": "112233",
"address": "경기 양평군",
"approve_required_status": 1,
"signup_introduction": "가입인사 꼭 남겨주세요.",
"setting_json": {
"fillPhone": "OPTIONAL",
"configName": "MANDATORY",
"fillGender": "MANDATORY",
"fillBirthDate": "NONE",
"fillActivityArea": "OPTIONAL",
"fillIntroduction": "OPTIONAL",
"fillMotivationToJoin": "OPTIONAL"
}
}
""";
type 'Null' is not a subtype of type 'String' in type cast
이런 에러가 계속 나면서 테스트가 계속 실패가 되고 있습니다.
nestedJson으로 구성한 setting_json을 제대로 파싱을 못하는거 같은데 어느 부분을 확인을 해보면 될까요?
답변 1
MVVM, 클린 아키텍처 관련 질문 있습니다.
0
85
2
가끔씩 ui가 깨지는? 현상이 있어서 질문드립니다.
0
91
1
freezed 3.0 대응된 코드 깃헙에도 업데이트 해주실 수 있으신가요?
0
176
3
sealed class 사용시 기능은 동작하지만 Radio위젯에 선택 표시가 안되는 부분 질문
0
117
2
sealed class 사용시 The getter 'orderType' isn't defined for the type 'NoteOrder<dynamic>' 오류
0
92
2
유즈케이스 관련하여 질문 드립니다.
0
91
1
mockito사용시 오류 해결법
1
122
2
sealed class 사용 문의2
0
74
2
sealed class 사용 문의
0
116
2
freezed3.0에서 build시 when생성되지 않습니다.
0
263
2
Try implementing the missing methods, or make the class abstract. 문제해결 공유
0
235
2
This is likely caused by a misconfigured builder definition. 오류 해결 방법
1
315
3
강의 화면이 안보여요
0
133
3
Flutter에서 추천하는 Navigator, Router
0
322
2
The following ProgressEvent object was thrown resolving an image codec: [object ProgressEvent]
0
324
3
event와 ui_event
0
211
1
코드 색깔 관련 질문
0
207
1
Photo.fleezed.dart,photo.g.dart삭제시 에러
0
203
2
sealed class 적용 시...
0
325
1
클린 아키텍처 질문
0
307
1
sealed class 데이터 접근
0
323
1
서버에서 데이터를 가져와서 사용하는 경우...
0
230
1
뷰/뷰모델 작성 질문
0
269
1
freezed JsonKey 사용 예시 공유
1
789
1





