Core: Feature suggestion: support property level normalization/denormalization context

Created on 2 May 2018  路  3Comments  路  Source: api-platform/core

Usage: being able to specify date formats on date times.

/**
 * @ApiProperty(
 *  attributes={
 *      "normalization_context": {
 *          "datetime_format": "Y-m-d"
 *      }
 *  }
 * )
 */

Secondary, could we default the date time format if the doctrine type was date as opposed to datetime?

enhancement help wanted

Most helpful comment

@raresserban It'd require property-level context support in Symfony Serializer first. Please open a feature request with Symfony if you're keen to see this happen.

Relevant comments:

All 3 comments

Steps that should make this work:

  1. create a new Normalizer that is

    • metadata-aware

    • supports datetime class

  2. parse metadata
  3. instantiate a DateTimeNormalizer with the format given as constructor argument

Currently I use the following workaround:

  • my own Date classes (extends DateTime) with __toString() methods to get proper format
  • my own DateTimeNormalizer (extends Syfmony's DateTimeNormalizer) to add to the supported types my own classes

No updates on this?

@raresserban It'd require property-level context support in Symfony Serializer first. Please open a feature request with Symfony if you're keen to see this happen.

Relevant comments:

Was this page helpful?
0 / 5 - 0 ratings