When simply GET a node/article, if this node has a custom Date (Only) field, this field will be serialized as String, e.g. "2017-04-18". It's a little bit surprising.

We need to do tests to find out:

1. Will a full Date field be serialized as "2017-04-18 12:00:00"?
2. Is this only JSONAPI behavior or REST module does the same thing?
3. Bug or By Design? Shall we increase some consistency between Date and Timestamp? (@e0ipso suggests to look into Scalars serialization)

Comments

skyredwang created an issue. See original summary.

wim leers’s picture

Title: Core Date field is serialized as String instead of timestamp/long » [PP-1] Core Date field is serialized as String instead of timestamp/long
Category: Support request » Bug report
Priority: Normal » Major
Status: Active » Postponed
Issue tags: +API-First Initiative, +Needs tests
Related issues: +#2926508: Add DateTimeNormalizer+TimestampNormalizer, deprecate TimestampItemNormalizer: @DataType-level normalizers are reusable by JSON:API

This is blocked on #2926508: Add DateTimeNormalizer+TimestampNormalizer, deprecate TimestampItemNormalizer: @DataType-level normalizers are reusable by JSON:API. Once that is fixed, this should be fixed too. The scope of this issue will then be to provide tests, to ensure BC.

e0ipso’s picture

Thanks for creating that core issue @Wim Leers. A workaround for the time being is to use JSON API Extras with the date field enhancers.

wim leers’s picture

wim leers’s picture

Oh wait, this is about DateTimeItem, not TimestampItem?

e0ipso’s picture

LOL, I had the same mixup in the jsonapi_extras issue queue @Wim Leers.

wim leers’s picture

Hm, it looks/sounds like you created a date field (DateTimeItem) that is configured to store only a date (\Drupal\datetime\Plugin\Field\FieldType\DateTimeItem::DATETIME_TYPE_DATE).

Then #2870609: [PP-1] Core Date field is serialized as String instead of timestamp/long is the relevant issue.

wim leers’s picture

wim leers’s picture

Status: Postponed » Closed (duplicate)