Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
@JsonIgnoreProperties(ignoreUnknown = true)Moshi的注释相当于什么?它是否默认忽略未知属性?
@JsonIgnoreProperties(ignoreUnknown = true)
默认情况下,Moshi 忽略 POJO 中未声明且存在于 JSON 中且不会引发任何错误的属性。
在这种情况下需要失败,failOnUnknown必须在适配器上明确设置。
failOnUnknown
例如 Moshi.Builder().build().adapter(MyClass::class.java).failOnUnknown()
Moshi.Builder().build().adapter(MyClass::class.java).failOnUnknown()