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.

Issue fork smart_date-3247537

Command icon 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

Mykola Dolynskyi created an issue. See original summary.

mykola dolynskyi’s picture

StatusFileSize
new16.77 KB
mykola dolynskyi’s picture

Issue summary: View changes
florisg’s picture

StatusFileSize
new4.73 KB

tested the patch,

patch unexpectedly ends in middle of line
patch: **** Only garbage was found in the patch input.

Rerolled the same logic against 3.4.x from git

florisg’s picture

Somehow in old git diff method the two new files didn't come up so rerolled in the new issue fork system.
That works awesome :)

mykola dolynskyi’s picture

Thanks, @florisg
*Patch-4 is incorrect, 2 files missing, I am hiding it out

shaldrupal’s picture

I 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.

"patches": {
	    "drupal/smart_date": {
		"SmartDate-Serialization issue Fixes": "https://www.drupal.org/files/issues/2021-11-03/3247537-restfull_api_serialization.patch"
	    }
	  } 
florisg’s picture

@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:

https://git.drupalcode.org/issue/smart_date-3247537/-/commit/5fe351f9ef93c494cfcd8d5bb98030e2effb82af.diff

or same patch with a prettyer url:

https://git.drupalcode.org/project/smart_date/-/merge_requests/11.diff
shaldrupal’s picture

thanks @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

mandclu’s picture

Status: Needs review » Reviewed & tested by the community

Based on the feedback from @shalDrupal marking this as RTBC

mandclu’s picture

Status: Reviewed & tested by the community » Fixed

I've merged this in, and will roll a new release shortly.

mykola dolynskyi’s picture

@mandclu, Thank you 🤝

Status: Fixed » Closed (fixed)

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