Serializer documentation can be improved (possibly contains an error?)
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 35/100
- Issue 类型
- 文档
- 描述清晰度
- 基本清楚
- 活跃度
- 冷清
- 技术栈
- php, symfony
调研方向
从 Symfony Serializer 文档页面开始,重点查看按项目更改序列化上下文的部分及其 decorator 示例。验证 getSupportedTypes 的缓存行为,并将其与提议的可扩展替代方案进行比较;当两个示例在技术上都正确,并且文档清楚说明何时使用每种方法时,即视为完成。
由索引模型根据 Issue 内容生成。
描述
2 part question, both relating to (Symfony) Serializer docs.
1:
The Serializer docs show an example of decorating the json-ld normalizer to add a few fields, but wouldn't a completely custom serializer be better so the getSupportedTypes can be used to efficiently decide if this serializer should be used instead of having 20,30, maybe 100s of services decorating the json-ld normalizer and it having to go through all those layers with like if (!$data instanceof ...) or if (!is_a($type, SomeClass::class, true))
Should we add an example for a cache-able/scalable solution that doesn't involve decorating the json-ld one?
2:
Then looking at the example code here:
https://api-platform.com/docs/core/serialization/#changing-the-serialization-context-on-a-per-item-basis-for-symfony
Specifically:
public function supportsNormalization($data, $format = null, array $context = [])
{
// Make sure we're not called twice
if (isset($context[self::ALREADY_CALLED])) {
return false;
}
return $data instanceof Book;
}
public function getSupportedTypes(?string $format): array
{
return [
Book::class => true
];
}
Returning true on getSupportedTypes means the usage of the serializer gets cached, and the supportsNormalization method is only checked once, then never again. So adding the self::ALREADY_CALLED in the normalize method doesn't do anything,... next time it goes through this normalizer, the supportsNormalization is skipped and boom, it now executed normalize on an item that has possibly already gone through it?
I can contribute a change for both things, but would like to get a second opinion first to see if I'm maybe missing something.
- 主要语言
- 没有语言数据
- 星标
- 181
- 派生
- 1.1k
- 平均合并
- 1 天 10 小时
- 30 天内合并 PR
- 24
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
api-platform/docs 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 85/100
api-platform/docs#2284 ·
-
难度 4/5 3-5 天 新手友好度 45/100
api-platform/docs#2318 ·
-
难度 4/5 3-5 天 新手友好度 45/100
api-platform/docs#2310 ·
-
Needs Work
难度 4/5 3-5 天 新手友好度 35/100
api-platform/docs#2133 · 9 条评论 · 1 个 reaction ·
-
good first issue
难度 1/5 1 小时以内 新手友好度 58/100
api-platform/docs#1450 · 2 条评论 ·
查看 api-platform/docs 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 75/100
-
certification
难度 1/5 1 小时以内 新手友好度 80/100
-
难度 1/5 1 小时以内 新手友好度 85/100
bisq-network/support#2181 ·
-
难度 1/5 1 小时以内 新手友好度 85/100
-
tutorial updates 未关闭
难度 1/5 1 小时以内 新手友好度 80/100
sveltejs/svelte.dev#2241 ·