Serializer documentation can be improved (possibly contains an error?)
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
- Tipo di issue
- Documentazione
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Tranquilla
- Stack tecnologico
- php, symfony
- Ambito
- documentation
Direzione di ricerca
Inizia dalla pagina della documentazione di Symfony Serializer, in particolare dalla sezione sulla modifica del contesto di serializzazione per elemento e dal relativo esempio di decorator. Verifica il comportamento di caching di getSupportedTypes e confrontalo con l’alternativa scalabile proposta; il lavoro è completo quando entrambi gli esempi sono tecnicamente corretti e la documentazione spiega chiaramente quando usare ciascun approccio.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- Nessun dato sulla lingua
- Stelle
- 181
- Fork
- 1.1k
- Merge medio
- 1g 10h
- PR unite (30g)
- 24
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di api-platform/docs
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
api-platform/docs#2284 ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
api-platform/docs#2318 ·
-
Graphql documentation Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
api-platform/docs#2310 ·
-
Needs Work
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
api-platform/docs#2133 · 9 commenti · 1 reazione ·
-
good first issue
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 58/100
api-platform/docs#1450 · 2 commenti ·
Tutte le issue di api-platform/docs
Issue simili
-
Area: Excel support
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
orbeon/orbeon-forms#7893 ·
-
Theme loads third-party resources on every page (jsdelivr web font, cdnjs Font Awesome) – GDPR Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
docToolchain/docToolchain#1705 ·
-
kb-infra-drift
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
OCHA-DAP/ds-knowledge-base#653 · 1 commento ·
-
area/dev-productivity area/disaster-recovery area/ipcei kind/enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
-
Claiming namespace: rasy007 Apertanamespace operations
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
EclipseFdn/open-vsx.org#13419 ·