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
Comment #2
wim leersThis 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.
Comment #3
e0ipsoThanks for creating that core issue @Wim Leers. A workaround for the time being is to use JSON API Extras with the date field enhancers.
Comment #4
wim leers#2926508: Add DateTimeNormalizer+TimestampNormalizer, deprecate TimestampItemNormalizer: @DataType-level normalizers are reusable by JSON:API now has a patch that should mostly work. See #2926508-4: Add DateTimeNormalizer+TimestampNormalizer, deprecate TimestampItemNormalizer: @DataType-level normalizers are reusable by JSON:API + #2926508-5: Add DateTimeNormalizer+TimestampNormalizer, deprecate TimestampItemNormalizer: @DataType-level normalizers are reusable by JSON:API.
TimestampItemfields in JSON API should then in theory get the same normalization as in core. Will need tests of course. And we'll first need to see whether we can get this to land in core at all.Comment #5
wim leersOh wait, this is about
DateTimeItem, notTimestampItem?Comment #6
e0ipsoLOL, I had the same mixup in the jsonapi_extras issue queue @Wim Leers.
Comment #7
wim leersHm, 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.
Comment #8
wim leersFFS copy/paste is fragile. The links in #7 obviously didn't make sense.
Comment #9
wim leersWe're fixing this in #2929932: Work around core's ill-designed @FieldType-level TimestampItemNormalizer normalization until #2926508 lands for
timestampfields. But it should also handledatetimeanddaterangefields, see #2929932-5: Work around core's ill-designed @FieldType-level TimestampItemNormalizer normalization until #2926508 lands.Comment #10
wim leers#2929932: Work around core's ill-designed @FieldType-level TimestampItemNormalizer normalization until #2926508 lands is now green and RTBC! Closing this as a duplicate now :)