When communicating with some APIs, it can happen that the JSON body may have duplicate fields which can cause the following error:
com.squareup.moshi.JsonDataException: Multiple values for 'name' at $.person.name
This can happen when the API delivers something similar to as follows:
{
"name" : "Chuck",
"age" : 21,
"name" : "Chuck"
}
How to handle such an issue?
I tried researching the web to see what I can find and found a similar answer here which handles duplicate data as a list and adding it together, but not showing a simple way as to how to ignore or overwrite it.
There is also confirmation that Moshi does not support this yet or may not even support it in the future as it is more of an issue with the API and not Moshi