AFAICT, Drupal\jsonapi\Normalizer\NormalizerBase doesn't need to override supportsNormalization() and supportsDenormalization(). Couldn't it achieve the same behavior by removing those overrides and only overriding checkFormat()?

CommentFileSizeAuthor
#7 3029891-7.patch1.94 KBwim leers
#7 interdiff.txt865 byteswim leers
#4 3029891-4.patch1.54 KBwim leers

Comments

effulgentsia created an issue. See original summary.

effulgentsia’s picture

For that matter, does it even need to override checkFormat(), or could it just change its protected $formats declaration to protected $format?

wim leers’s picture

Title: Simplify Drupal\jsonapi\Normalizer\NormalizerBase » Clean-up: simplify Drupal\jsonapi\Normalizer\NormalizerBase thanks to #2863778
Assigned: Unassigned » wim leers
Issue tags: +API-First Initiative
Related issues: +#2821556: [CLEANUP] Remove dependency on HAL, +#2863778: Clean up \Drupal\hal\Normalizer\NormalizerBase: duplicate less from the parent class \Drupal\serialization\Normalizer\NormalizerBase

Another nice find!

JSON:API started duplicating this in #2821556: [CLEANUP] Remove dependency on HAL. But that's only because it removed its dependency on the HAL module, which included overrides for those methods in \Drupal\hal\Normalizer\NormalizerBase. To simplify refactoring, @e0ipso chose to keep that logic.

But then about six months later, core cleaned up \Drupal\hal\Normalizer\NormalizerBase in #2863778: Clean up \Drupal\hal\Normalizer\NormalizerBase: duplicate less from the parent class \Drupal\serialization\Normalizer\NormalizerBase. That's also where protected $format was introduced in \Drupal\serialization\Normalizer\NormalizerBase.

So this was simply a matter of JSON:API taking the prudent road. It's cool to see that #2863778 indeed did not break BC for JSON:API, thanks to JSON:API owning the bits it cared about :)

Conclusion: +1 to everything you said, but it's only thanks to core getting better that we can do this!

wim leers’s picture

Status: Active » Needs review
StatusFileSize
new1.54 KB
wim leers’s picture

@e0ipso: I ran all JSON:API Extras tests locally, they still pass 👍

Status: Needs review » Needs work

The last submitted patch, 4: 3029891-4.patch, failed testing. View results

wim leers’s picture

Assigned: wim leers » Unassigned
Status: Needs work » Needs review
StatusFileSize
new865 bytes
new1.94 KB

You may be surprised to read this, but I love that failure! 🥰

Why?

Because it proves that the change above suddenly allowed JSON:API's forward port of #2926508: Add DateTimeNormalizer+TimestampNormalizer, deprecate TimestampItemNormalizer: @DataType-level normalizers are reusable by JSON:API to be used for formats other than JSON:API, which caused these test failures in the one place where the JSON:API is using core's serializer with ::normalize($format=NULL).

So: we do need ::checkFormat(), but for a very good reason (to be and continue to be self-contained), which is now explicitly documented :)

gabesullice’s picture

Status: Needs review » Reviewed & tested by the community

Nice! No more reflection, less "vendored" code to babysit. LGTM.

  • Wim Leers committed 7df373b on 8.x-2.x
    Issue #3029891 by Wim Leers, effulgentsia, gabesullice: Clean-up:...
wim leers’s picture

Status: Reviewed & tested by the community » Fixed

🚢

effulgentsia’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.