Ask Your Question
1

When the library throws a JsonDataException, why does the Kotlin Moshi adapter return null?

asked 2021-07-15 11:00:00 +0000

plato gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2021-09-17 16:00:00 +0000

scrum gravatar image

The Kotlin Moshi adapter returns null when the library throws a JsonDataException because Moshi's default behavior when it encounters invalid JSON is to return null. This behavior can be customized by providing a custom JSON adapter or by using Moshi's lenient mode. In lenient mode, Moshi will attempt to parse the JSON even if it contains errors, but it may produce unexpected results. Generally, it's better to fix the underlying JSON data to avoid JsonDataException errors rather than relying on lenient mode or custom adapters to handle them.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-07-15 11:00:00 +0000

Seen: 11 times

Last updated: Sep 17 '21