What's the equivalent of the annotation @JsonIgnoreProperties(ignoreUnknown = true)
for Moshi? Does it ignore unknown properties by default or not?
Asked
Active
Viewed 811 times
1

Bencri
- 1,173
- 1
- 7
- 22
-
https://stackoverflow.com/questions/36204499/moshi-ignore-field – Saurabh Thorat Jul 23 '20 at 15:37
-
I don't want to exclude a specific field, I want to exclude all fields that are not declared in my POJO class, so that it doesn't break on api changes. – Bencri Jul 23 '20 at 16:22
1 Answers
3
Moshi by default ignore's properties that are not declared in POJO's and are present in JSON without throwing any error.
Incase failure is desired in such case, failOnUnknown
has to be set explicitly on the adapter.
For e.g.
Moshi.Builder().build().adapter(MyClass::class.java).failOnUnknown()

farhan patel
- 1,490
- 2
- 19
- 30