question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Extract common features from normalizer to be able to decorate them easily

See original GitHub issue

Currently JSON and JSON-LD are handled by two different normalizers, both of them extending ApiPlatform\Core\Serializer\AbstractItemNormalizer.

I wanted to add/modify properties on one of my resources (eg. setting URLs for images managed by LiipImagineBundle) and could not find a way to do it without decorating both api_platform.serializer.normalizer.item and api_platform.jsonld.normalizer.item:

    app.normalizer.image:
        class: AppBundle\Serializer\ImageNormalizer
        decorates: 'api_platform.serializer.normalizer.item'
        arguments:
            - '@app.normalizer.image.inner'
            (...)

    app.normalizer.jsonld.image:
        class: AppBundle\Serializer\ImageNormalizer
        decorates: 'api_platform.jsonld.normalizer.item'
        arguments:
            - '@app.normalizer.jsonld.image.inner'
            (...)

Wouldn’t it make sense to have a common item normalizer injected in every other item normalizers and be able to only decorate that one?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

6reactions
Lyrkancommented, Jun 7, 2017

@soyuka Wouldn’t it be possible to keep the normalizers separated but still having a “base” normalizer used by all of them ?

There is already a big part of the code that is shared between them (ApiPlatform\Core\Serializer\AbstractItemNormalizer) so at first I was expecting something like:

  • api_platform.serializer.normalizer.item: do the common things, basically what AbstractItemNormalizer does nowadays
  • api_platform.json.normalizer.item: uses api_platform.serializer.normalizer.item (the same way it calls parent::denormalize at the end of its own denormalize method) and does specific things
  • api_platform.jsonld.normalizer.item: same thing but with jsonld specific parts
  • api_platform.hal.normalizer.item: same thing but with hal specific parts

That would still allow people to only decorate json/jsonld/hal normalizers if needed, or decorate the common normalizer for properties that must be added/modified in every formats.

3reactions
teohhanhuicommented, Jun 7, 2017

If we can find a way of refactoring to extract out common functionality, I say go ahead. 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

All about Feature Scaling - Towards Data Science
The most common techniques of feature scaling are Normalization and Standardization. Normalization is used when we want to bound our values ...
Read more >
8 Feature Engineering Techniques for Machine Learning
Understand what is feature engineering and why is it important for machine learning and explore a list of top feature engineering techniques ...
Read more >
Feature Extraction Techniques - NLP - GeeksforGeeks
This article focuses on basic feature extraction techniques in NLP to analyse the similarities between pieces of text.
Read more >
How and why do normalization and feature scaling work?
It's simply a case of getting all your data on the same scale: if the scales for different features are wildly different, this...
Read more >
Speech Recognition — Feature Extraction MFCC & PLP
It is easier to develop models and to train these models with independent features. One popular audio feature extraction method is the Mel-frequency ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found