docs(lesson6): add ignoreUnknownKeys rationale for backend schema changes
This commit is contained in:
1 parent
a3d4bc9429
commit
dc2e32c437
1 file changed
+12
@@ -92,6 +92,18 @@ install(ContentNegotiation) {
|
|||||||
|
|
||||||
如果不加这两个依赖,`body<List<Product>>()` 这类写法会失败(无法自动解析 JSON)。
|
如果不加这两个依赖,`body<List<Product>>()` 这类写法会失败(无法自动解析 JSON)。
|
||||||
|
|
||||||
|
另外,`ignoreUnknownKeys = true` 的作用是:
|
||||||
|
- 当后端返回了“数据类里未定义的字段”时,不报错,直接忽略。
|
||||||
|
- 适合课堂联调和后端字段可能变动的阶段,提升稳定性。
|
||||||
|
|
||||||
|
示例:
|
||||||
|
- `Product` 只定义了 `id/title`
|
||||||
|
- 后端额外返回 `tag/extra`
|
||||||
|
- 开启 `ignoreUnknownKeys = true` 后,`id/title` 仍可正常解析。
|
||||||
|
|
||||||
|
> 你在官方文档里看到的 `prettyPrint`、`isLenient` 只是配置示例,
|
||||||
|
> `ignoreUnknownKeys` 同样是 JsonBuilder 的常用配置项。
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 四、共享模型(第2段:10分钟)
|
## 四、共享模型(第2段:10分钟)
|
||||||
|
|||||||
Reference in new issue
Block a user