Skip to content

10.3.0

Latest

Choose a tag to compare

@joelwurtz joelwurtz released this 16 Sep 13:14
· 8 commits to main since this release
1bc9c70

Added

  • Allow to disable group checking globally or per mapper, instead of only per property
  • Add a symfony/json-streamer integration: the AutoMapper can now read and write JSON streams,
    keeping all its mapping features available while streaming. Enable it in the bundle with the
    json_streamer.enabled option, which decorates the Symfony reader and writer and keeps them as a
    fallback for the types the AutoMapper does not handle. Use json_streamer.only_registered_mapping
    to restrict it to the registered mappings. See the documentation
  • Add a json side to the mappers, naming the JSON document itself symmetrically in both
    directions: a json -> class mapper reads a JSON stream, a class -> json mapper writes one.
    Both are only reachable through the JsonStreamer integration, map() still refuses them
  • Add a MapperContext::STREAM option, to read and write collections without buffering them, so the
    memory usage stays flat whatever the collection size
  • Add an arrayLike option on the #[Mapper] attribute, to read or write a class as a keyed array
    shape (dynamic keys, ArrayAccess, ...) instead of a typed object. The array-like decision is now
    resolved once during metadata discovery and reused everywhere, instead of being guessed from the
    source and target names

Changed

These are bug fixes, but they change the output of mappings that already worked:

  • Convert between different backed enums through their backing value instead of copying the source instance
  • Keep the concrete Symfony Uid subclass (e.g. UuidV4) when copying a uid instead of building a base Uuid/Ulid
  • Keep the concrete date time subclass in date time to date time mapping instead of always building DateTime/DateTimeImmutable
  • The AutoMapperNormalizer no longer claims value objects handled by dedicated symfony normalizers (DateTimeInterface, BackedEnum, AbstractUid, etc.), which could produce a structure dump instead of the expected representation
  • The highest priority Mapper attribute wins as documented, instead of the lowest

Fixed

  • Resolve API Platform IRIs in every JSON format, not only JSON-LD, so a relation sent as an IRI on application/json or application/merge-patch+json no longer reaches the mapper as a raw string
  • Use the MapFrom attribute reference instead of MapTo when resolving transformers in MapFromListener
  • Do not run a transformation on a null source value when the target is not nullable, a TypeError is thrown for typed properties instead of the transformation crashing on the null value
  • Create backed enum from scalar source value instead of assigning the raw scalar
  • Normalize leading backslash in class names resolved from docblocks, fixing a parse error in generated mappers for global namespace classes and the __PM__ proxy name off-by-one
  • Implement CheckTypeInterface on enum, date-time and uid transformers so union source types generate a runtime check for every branch
  • Unwrap nullable doctrine collection target type, items are mapped to the collection value type instead of plain arrays
  • Capture the context in the isAllowedAttribute closure, fixing MapToContext combined with skip_null_values
  • Guard nested property accessors (parent.child) against null or uninitialized parent values on read, write and constructor paths, support private nested leaf properties and nullable parent types
  • Support variadic constructor parameters, values are spread as individual arguments and an absent variadic no longer throws MissingConstructorArgumentsException
  • Correct identifier hashing: scalar identifiers are cast to string, object identifiers are hashed through their own mapper and hash_final no longer receives a string as its boolean argument, fixing mappers generated with strictTypes: true
  • Atomic mapper file writes and locked registry updates in FileLoader, fixing partially written files and lost registry entries under concurrency, the cache warmer no longer discards previously registered mapper hashes
  • Initialize LazyMap only once instead of re-running the mapping on every access
  • Align Map attribute if condition semantics with symfony/object-mapper: if: false never maps the property, callables receive the value first and class level Map targets also match child classes
  • Do not register the cache warmer when the eval loader is enabled, fixing container compilation with automapper.loader.eval: true
  • Detect doctrine entities even when their metadata is not loaded yet, fixing missing provider and identifier on cold metadata factories
  • Do not map static properties
  • Guard a single matching union branch at runtime so a value of an unhandled union member is not blindly transformed
  • Use the computed resource class in the API Platform JSON-LD context transformer instead of resolving it from a non-resource source (operator precedence fix)
  • Only shorten an API Platform resource to its id for array or mixed targets, avoiding a TypeError on scalar targets
  • Allow final and static public getters to be used with #[MapToContext]
  • Run the object mapper listeners after the Doctrine and discriminator listeners in the bundle, so a Map-attributed source class keeps its Doctrine provider and discriminator handling
  • The JsonStreamer integration no longer claims enums and uids, which were read as null and written as a structure dump ({"name":"FLAT","value":"flat"}) instead of being delegated to the Symfony reader and writer