Skip to content

[Fix] 마이페이지 dto 달라서 파싱 안되는 에러#481

Open
HI-JIN2 wants to merge 2 commits intodevelopfrom
fix/serialization-ignore-unknown-keys
Open

[Fix] 마이페이지 dto 달라서 파싱 안되는 에러#481
HI-JIN2 wants to merge 2 commits intodevelopfrom
fix/serialization-ignore-unknown-keys

Conversation

@HI-JIN2
Copy link
Member

@HI-JIN2 HI-JIN2 commented Feb 27, 2026

Summary

  • 마이페이지 DTO가 바뀌었음 (언제인지 모름)
  • ignoreUnknownKeys = true 옵션을 키지 않았었으므로 DTO에 정의되지 않은 필드가 있을시 ApiResultCall - onFailure called 로 간주됨 (앱이 터지지는 않음)
  • 마이페이지 api의 경우 로그인시 웰컴 토스트를 띄우기 위해서 호출하지만 해당 작업이 onFailure임으로 토스트 안뜸. 마이페이지 화면에서도 실패로 간주 (앱이 터지지는 않으나 uistate가 success하지 못함)
  kotlinx.serialization.json.internal.JsonDecodingException: Unexpected JSON token at offset 102: Encountered an unknown key 'departmentId' at path: $.result.provider
    Use 'ignoreUnknownKeys = true' in 'Json {}' builder to ignore unknown keys.
    JSON input: {"isSuccess":true,"code":1000,"message":"요청에 성공하였습니다.","result":{"nickname":"use","provider":"KAKAO","departmentId":49,"departmentName":"컴퓨터학부","collegeId":8,"collegeName":"IT대학"}}
                                                                                                

Describe your changes

  • 마이페이지 DTO를 맞게 수정해줬음

To Reviewer

좀 불안해서 그러는데 ignoreUnknownKeys = true 옵션을 키는게 어떠할지 제안드립니다..!

https://dongx2.tistory.com/125

Enable ignoreUnknownKeys in Retrofit Json to prevent crashes when backend adds new fields (e.g., departmentId/collegeId in mypage response).
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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

  • Problem Addressed: The application was crashing with a JsonDecodingException when backend responses included additional fields not defined in the Data Transfer Objects (DTOs).
  • Solution Implemented: The ignoreUnknownKeys property has been set to true in the shared Json instance, which is utilized by the Retrofit converter.
  • Impact: This change ensures client-side forward compatibility with additive changes to server responses, preventing crashes from unexpected JSON fields.

🧠 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
  • app/src/main/java/com/eatssu/android/di/NetworkModule.kt
    • Enabled ignoreUnknownKeys for the Json instance provided by provideJson().
Activity
  • No specific activity has been recorded for this pull request yet.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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

@HI-JIN2 HI-JIN2 changed the title fix: ignore unknown JSON keys in serialization [Fix] 마이페이지 dto 달라서 파싱 안되는 에러 Feb 27, 2026
@HI-JIN2 HI-JIN2 self-assigned this Feb 27, 2026
@HI-JIN2 HI-JIN2 requested a review from PeraSite February 27, 2026 17:52
@PeraSite
Copy link
Member

요구하는 필드보다 더 있다고 비즈니스 로직에 크게 영향을 주진 않으니 ignoreUnknownKeys = true로 해도 될 것 같습니다!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants