Conversation
Enable ignoreUnknownKeys in Retrofit Json to prevent crashes when backend adds new fields (e.g., departmentId/collegeId in mypage response).
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the application's robustness by configuring the JSON deserialization process to gracefully handle unexpected fields in API responses. By ignoring unknown keys, the application will no longer crash when the backend introduces new data fields, thereby improving stability and maintaining compatibility with evolving server-side APIs. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request correctly addresses application crashes caused by unknown keys in JSON responses by setting ignoreUnknownKeys = true. This is a good practice for ensuring forward compatibility with server-side API changes. I've added one suggestion to further improve the robustness of the JSON parsing by also coercing input values, which would prevent crashes from other types of unexpected data like null for non-nullable fields.
| @Singleton | ||
| @Provides | ||
| fun provideJson(): Json = Json { | ||
| ignoreUnknownKeys = true |
There was a problem hiding this comment.
To further improve parsing robustness, consider also setting coerceInputValues = true. This will prevent crashes if the API sends null for a non-nullable field by coercing it to a default value (e.g., 0 for Int, "" for String). This aligns well with the goal of making the client more resilient to API changes.
ignoreUnknownKeys = true
coerceInputValues = true|
요구하는 필드보다 더 있다고 비즈니스 로직에 크게 영향을 주진 않으니 ignoreUnknownKeys = true로 해도 될 것 같습니다! |
Summary
ignoreUnknownKeys = true옵션을 키지 않았었으므로 DTO에 정의되지 않은 필드가 있을시 ApiResultCall - onFailure called 로 간주됨 (앱이 터지지는 않음)Describe your changes
To Reviewer
좀 불안해서 그러는데
ignoreUnknownKeys = true옵션을 키는게 어떠할지 제안드립니다..!https://dongx2.tistory.com/125