Problem/Motivation
In latest version of Drupal and Smart Date module RESTful API on POST operation on entity with SmartDate filed type with application/hal+json fails with
{
"message": "Unprocessable Entity: validation failed.\nfield_time.0.end_value: This value should not be null.\n"
}
where field_time is the name of added SmartDate field to the entity.
Earlier was the patch for support of HAL serialization, and seems it was working, but stopped after TimeStampItemNormalizerTrait was removed from the module as deprecated.
I have traced symfony vendor/symfony/serializer/Serializer.php::denormalize() is not calling SmartDateNormalizer denormalize() anymore and callstack ends on TimestampNormalizer.
So I took Drupal\Core\TypedData\Plugin\DataType\Timestamp and its normalizers for Timestamp and TimestampItem from HAL and Serialization core modules as an example for new implementation.
Also as deprecated TimeStampItemNormalizerTrait page recommends \Drupal\serialization\Normalizer\TimestampNormalizer instead - it is involved now.
(BTW, not sure if initial inheriting Timestamp instead of Drupal\Core\TypedData\ComplexDataDefinitionBase which implements \Drupal\Core\TypedData\Type\DateTimeInterface was correct, but I was not refactoring that)/
Steps to reproduce
- enable serialization and hal modules
- add SmartDate field to entity
- perform RESTful API POST call with curl providing field values for new entity, including new SmartDate field
- get the "Unprocessable Entity: validation failed.\nfield_time.0.end_value: This value should not be null.\n" response
Proposed resolution
patch. Details in first section.
Remaining tasks
none. Initial inheritance from Timestamp seems under doubt.
User interface changes
none.
API changes
none.
Data model changes
none.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 3247537-restfull_api_serialization.patch | 16.77 KB | mykola dolynskyi |
Issue fork smart_date-3247537
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
mykola dolynskyiComment #3
mykola dolynskyiComment #4
florisg commentedtested the patch,
Rerolled the same logic against 3.4.x from git
Comment #5
florisg commentedSomehow in old git diff method the two new files didn't come up so rerolled in the new issue fork system.
That works awesome :)
Comment #7
mykola dolynskyiThanks, @florisg
*Patch-4 is incorrect, 2 files missing, I am hiding it out
Comment #8
shaldrupal commentedI tried this patch: https://www.drupal.org/files/issues/2021-11-03/3247537-restfull_api_seri... in my local setup but nothing happened.
Composer nothing is showing there belong the patch, I used this way to call the patch, please suggest if anything wrong there.
Comment #9
florisg commented@shalDrupal that's not the right patch, test it with the pull request:
https://git.drupalcode.org/issue/smart_date-3247537/
Converting a merge request into a `traditional` patch is as easy as adding `.diff` at the end of the commit url.
so in this case:
or same patch with a prettyer url:
Comment #10
shaldrupal commentedthanks @florisg I tried your patch and its works perfectly, also tried same on postman and entry successfully created.
confirmed merge request and #9 works for me
Comment #11
mandclu commentedBased on the feedback from @shalDrupal marking this as RTBC
Comment #13
mandclu commentedI've merged this in, and will roll a new release shortly.
Comment #14
mykola dolynskyi@mandclu, Thank you 🤝