- Deprecate the
csv_escape_char
context option ofCsvEncoder
, theCsvEncoder::ESCAPE_CHAR_KEY
constant and theCsvEncoderContextBuilder::withEscapeChar()
method, following its deprecation in PHP 8.4 - Add
SnakeCaseToCamelCaseNameConverter
- Support subclasses of
\DateTime
and\DateTimeImmutable
for denormalization - Add the
UidNormalizer::NORMALIZATION_FORMAT_RFC9562
constant - Add support for configuring multiple serializer instances with different default contexts, name converters, sets of normalizers and encoders
- Add support for collection profiles of multiple serializer instances
- Deprecate
AdvancedNameConverterInterface
, useNameConverterInterface
instead
- Add arguments
$class
,$format
and$context
toNameConverterInterface::normalize()
andNameConverterInterface::denormalize()
- Add
DateTimeNormalizer::CAST_KEY
context option - Add
AbstractNormalizer::FILTER_BOOL
context option - Add
CamelCaseToSnakeCaseNameConverter::REQUIRE_SNAKE_CASE_PROPERTIES
context option - Deprecate
AbstractNormalizerContextBuilder::withDefaultContructorArguments(?array $defaultContructorArguments)
, usewithDefaultConstructorArguments(?array $defaultConstructorArguments)
instead (note the missings
character in Contructor word in deprecated method) - Add
XmlEncoder::CDATA_WRAPPING_PATTERN
context option
- Add method
getSupportedTypes()
toDenormalizerInterface
andNormalizerInterface
- Remove denormalization support for
AbstractUid
inUidNormalizer
, use one ofAbstractUid
child class instead - Denormalizing to an abstract class in
UidNormalizer
now throws an\Error
- Remove
ContextAwareDenormalizerInterface
, useDenormalizerInterface
instead - Remove
ContextAwareNormalizerInterface
, useNormalizerInterface
instead - Remove
CacheableSupportsMethodInterface
, useNormalizerInterface
andDenormalizerInterface
instead - Require explicit argument when calling
AttributeMetadata::setSerializedName()
andClassMetadata::setClassDiscriminatorMapping()
- Add argument
$context
toNormalizerInterface::supportsNormalization()
andDenormalizerInterface::supportsDenormalization()
- Remove Doctrine annotations support in favor of native attributes
- Remove
AnnotationLoader
, useAttributeLoader
instead
- Add
TranslatableNormalizer
- Allow
Context
attribute to target classes - Deprecate Doctrine annotations support in favor of native attributes
- Allow the
Groups
attribute/annotation on classes - JsonDecode: Add
json_decode_detailed_errors
option - Make
ProblemNormalizer
give details about Messenger'sValidationFailedException
- Add
XmlEncoder::CDATA_WRAPPING
context option - Deprecate
AnnotationLoader
, useAttributeLoader
instead - Add aliases for all classes in the
Annotation
namespace toAttribute
- Add
AbstractNormalizer::REQUIRE_ALL_PROPERTIES
context flag to require all properties to be listed in the input instead of falling back to null for nullable ones - Add
XmlEncoder::SAVE_OPTIONS
context option - Add
BackedEnumNormalizer::ALLOW_INVALID_VALUES
context option - Add
UnsupportedFormatException
which is thrown when there is no decoder for a given format - Add method
getSupportedTypes(?string $format)
toNormalizerInterface
andDenormalizerInterface
- Make
ProblemNormalizer
give details aboutValidationFailedException
andPartialDenormalizationException
- Deprecate
CacheableSupportsMethodInterface
in favor of the newgetSupportedTypes(?string $format)
methods - The following Normalizer classes will become final in 7.0:
ConstraintViolationListNormalizer
CustomNormalizer
DataUriNormalizer
DateIntervalNormalizer
DateTimeNormalizer
DateTimeZoneNormalizer
GetSetMethodNormalizer
JsonSerializableNormalizer
ObjectNormalizer
PropertyNormalizer
- Add support for constructor promoted properties to
Context
attribute - Add context option
PropertyNormalizer::NORMALIZE_VISIBILITY
with bitmask flagsPropertyNormalizer::NORMALIZE_PUBLIC
,PropertyNormalizer::NORMALIZE_PROTECTED
,PropertyNormalizer::NORMALIZE_PRIVATE
- Add method
withNormalizeVisibility
toPropertyNormalizerContextBuilder
- Deprecate calling
AttributeMetadata::setSerializedName()
,ClassMetadata::setClassDiscriminatorMapping()
without arguments - Change the signature of
AttributeMetadataInterface::setSerializedName()
tosetSerializedName(?string)
- Change the signature of
ClassMetadataInterface::setClassDiscriminatorMapping()
tosetClassDiscriminatorMapping(?ClassDiscriminatorMapping)
- Add option YamlEncoder::YAML_INDENTATION to YamlEncoder constructor options to configure additional indentation for each level of nesting. This allows configuring indentation in the service configuration.
- Add
SerializedPath
annotation to flatten nested attributes
- Add
TraceableSerializer
,TraceableNormalizer
,TraceableEncoder
andSerializerDataCollector
to integrate with the web profiler - Add the ability to create contexts using context builders
- Set
Context
annotation as not final - Deprecate
ContextAwareNormalizerInterface
, useNormalizerInterface
instead - Deprecate
ContextAwareDenormalizerInterface
, useDenormalizerInterface
instead - Deprecate supporting denormalization for
AbstractUid
inUidNormalizer
, use one ofAbstractUid
child class instead - Deprecate denormalizing to an abstract class in
UidNormalizer
- Add support for
can*()
methods toObjectNormalizer
- Remove
ArrayDenormalizer::setSerializer()
, callsetDenormalizer()
instead - Remove the ability to create instances of the annotation classes by passing an array of parameters, use named arguments instead
- Add support of PHP backed enumerations
- Add support for serializing empty array as object
- Return empty collections as
ArrayObject
fromSerializer::normalize()
whenPRESERVE_EMPTY_OBJECTS
is set - Add support for collecting type errors during denormalization
- Add missing arguments in
MissingConstructorArgumentsException
- Add the ability to provide (de)normalization context using metadata (e.g.
@Symfony\Component\Serializer\Annotation\Context
) - Deprecate
ArrayDenormalizer::setSerializer()
, callsetDenormalizer()
instead - Add normalization formats to
UidNormalizer
- Add
CsvEncoder::END_OF_LINE
context option - Deprecate creating instances of the annotation classes by passing an array of parameters, use named arguments instead
- added
CompiledClassMetadataFactory
andClassMetadataFactoryCompiler
for faster metadata loading. - added
UidNormalizer
- added
FormErrorNormalizer
- added
MimeMessageNormalizer
- serializer mapping can be configured using php attributes
- added support for scalar values denormalization
- added support for
\stdClass
toObjectNormalizer
- added the ability to ignore properties using metadata (e.g.
@Symfony\Component\Serializer\Annotation\Ignore
) - added an option to serialize constraint violations payloads (e.g. severity)
- throw an exception when creating a
Serializer
with normalizers which neither implementNormalizerInterface
norDenormalizerInterface
- throw an exception when creating a
Serializer
with encoders which neither implementEncoderInterface
norDecoderInterface
- changed the default value of the
CsvEncoder
"as_collection" option totrue
- removed
AbstractNormalizer::$circularReferenceLimit
,AbstractNormalizer::$circularReferenceHandler
,AbstractNormalizer::$callbacks
,AbstractNormalizer::$ignoredAttributes
,AbstractNormalizer::$camelizedAttributes
,AbstractNormalizer::setCircularReferenceLimit()
,AbstractNormalizer::setCircularReferenceHandler()
,AbstractNormalizer::setCallbacks()
andAbstractNormalizer::setIgnoredAttributes()
, use the default context instead. - removed
AbstractObjectNormalizer::$maxDepthHandler
andAbstractObjectNormalizer::setMaxDepthHandler()
, use the default context instead. - removed
XmlEncoder::setRootNodeName()
&XmlEncoder::getRootNodeName()
, use the default context instead. - removed individual encoders/normalizers options as constructor arguments.
- removed support for instantiating a
DataUriNormalizer
with a default MIME type guesser when thesymfony/mime
component isn't installed. - removed the
XmlEncoder::TYPE_CASE_ATTRIBUTES
constant. UseXmlEncoder::TYPE_CAST_ATTRIBUTES
instead.
- deprecated the
XmlEncoder::TYPE_CASE_ATTRIBUTES
constant, useXmlEncoder::TYPE_CAST_ATTRIBUTES
instead - added option to output a UTF-8 BOM in CSV encoder via
CsvEncoder::OUTPUT_UTF8_BOM_KEY
context option - added
ProblemNormalizer
to normalize errors according to the API Problem spec (RFC 7807)
- added the list of constraint violations' parameters in
ConstraintViolationListNormalizer
- added support for serializing
DateTimeZone
objects - added a
deep_object_to_populate
context option to recursive denormalize onobject_to_populate
object.
- using the default context is the new recommended way to configure normalizers and encoders
- added a
skip_null_values
context option to not serialize properties with anull
values AbstractNormalizer::handleCircularReference
is now final and receives two optional extra arguments: the format and the context- added support for XML comment encoding (encoding
['#comment' => ' foo ']
results<!-- foo -->
) - added optional
int[] $encoderIgnoredNodeTypes
argument toXmlEncoder::__construct
to configure node types to be ignored during encoding - added
AdvancedNameConverterInterface
to access the class, the format and the context in a name converter - the
AbstractNormalizer::handleCircularReference()
method will have two new$format
and$context
arguments in version 5.0, not defining them is deprecated - deprecated creating a
Serializer
with normalizers which do not implement eitherNormalizerInterface
orDenormalizerInterface
- deprecated creating a
Serializer
with normalizers which do not implement eitherNormalizerInterface
orDenormalizerInterface
- deprecated creating a
Serializer
with encoders which do not implement eitherEncoderInterface
orDecoderInterface
- added the optional
$objectClassResolver
argument inAbstractObjectNormalizer
andObjectNormalizer
constructor - added
MetadataAwareNameConverter
to configure the serialized name of properties through metadata YamlEncoder
now handles the.yml
extension tooAbstractNormalizer::$circularReferenceLimit
,AbstractNormalizer::$circularReferenceHandler
,AbstractNormalizer::$callbacks
,AbstractNormalizer::$ignoredAttributes
,AbstractNormalizer::$camelizedAttributes
,AbstractNormalizer::setCircularReferenceLimit()
,AbstractNormalizer::setCircularReferenceHandler()
,AbstractNormalizer::setCallbacks()
andAbstractNormalizer::setIgnoredAttributes()
are deprecated, use the default context instead.AbstractObjectNormalizer::$maxDepthHandler
andAbstractObjectNormalizer::setMaxDepthHandler()
are deprecated, use the default context instead.- passing configuration options directly to the constructor of
CsvEncoder
,JsonDecode
andXmlEncoder
is deprecated since Symfony 4.2, use the default context instead.
- added
CacheableSupportsMethodInterface
for normalizers and denormalizers that use only the type and the format in theirsupports*()
methods - added
MissingConstructorArgumentsException
new exception for deserialization failure of objects that needs data insertion in constructor - added an optional
default_constructor_arguments
option of context to specify a default data in case the object is not initializable by its constructor because of data missing - added optional
bool $escapeFormulas = false
argument toCsvEncoder::__construct
- added
AbstractObjectNormalizer::setMaxDepthHandler
to set a handler to call when the configured maximum depth is reached - added optional
int[] $ignoredNodeTypes
argument toXmlEncoder::__construct
. XML decoding now ignores comment node types by default. - added
ConstraintViolationListNormalizer
- removed the
SerializerAwareEncoder
andSerializerAwareNormalizer
classes, use theSerializerAwareTrait
instead - removed the
Serializer::$normalizerCache
andSerializer::$denormalizerCache
properties - added an optional
string $format = null
argument toAbstractNormalizer::instantiateObject
- added an optional
array $context = []
toSerializer::supportsNormalization
,Serializer::supportsDenormalization
,Serializer::supportsEncoding
andSerializer::supportsDecoding
- added
AbstractObjectNormalizer::DISABLE_TYPE_ENFORCEMENT
context option to disable throwing anUnexpectedValueException
on a type mismatch - added support for serializing
DateInterval
objects - added getter for extra attributes in
ExtraAttributesException
- improved
CsvEncoder
to handle variable nested structures - CSV headers can be passed to the
CsvEncoder
via thecsv_headers
serialization context variable - added
$context
when checking for encoding, decoding and normalizing inSerializer
- added
SerializerPass
- added support for serializing objects that implement
JsonSerializable
- added the
DenormalizerAwareTrait
andNormalizerAwareTrait
traits to support normalizer/denormalizer awareness - added the
DenormalizerAwareInterface
andNormalizerAwareInterface
interfaces to support normalizer/denormalizer awareness - added a PSR-6 compatible adapter for caching metadata
- added a
MaxDepth
option to limit the depth of the object graph when serializing objects - added support for serializing
SplFileInfo
objects - added support for serializing objects that implement
DateTimeInterface
- added
AbstractObjectNormalizer
as a base class for normalizers that deal with objects - added support to relation deserialization
- added support for serialization and deserialization groups including annotations, XML and YAML mapping.
- added
AbstractNormalizer
to factorise code and ease normalizers development - added circular references handling for
PropertyNormalizer
- added support for a context key called
object_to_populate
inAbstractNormalizer
to reuse existing objects in the deserialization process - added
NameConverterInterface
andCamelCaseToSnakeCaseNameConverter
- [DEPRECATION]
GetSetMethodNormalizer::setCamelizedAttributes()
andPropertyNormalizer::setCamelizedAttributes()
are replaced byCamelCaseToSnakeCaseNameConverter
- [DEPRECATION] the
Exception
interface has been renamed toExceptionInterface
- added
ObjectNormalizer
leveraging thePropertyAccess
component to normalize objects containing both properties and getters / setters / issers / hassers methods. - added
xml_type_cast_attributes
context option for allowing users to opt-out of typecasting xml attributes.
- added a new serializer:
PropertyNormalizer
. LikeGetSetMethodNormalizer
, this normalizer will map an object's properties to an array. - added circular references handling for
GetSetMethodNormalizer
- added support for
is.*
getters inGetSetMethodNormalizer
- added
$context
support for XMLEncoder. - [DEPRECATION] JsonEncode and JsonDecode where modified to throw
an exception if error found. No need for
get*Error()
functions
- added
GetSetMethodNormalizer::setCamelizedAttributes
to allow calling camel cased methods for underscored properties
- [BC BREAK] All Serializer, Normalizer and Encoder interfaces have been
modified to include an optional
$context
array parameter. - The XML Root name can now be configured with the
xml_root_name
parameter in the context option to theXmlEncoder
. - Options to
json_encode
andjson_decode
can be passed through the context options ofJsonEncode
andJsonDecode
encoder/decoders.
-
added DecoderInterface::supportsDecoding(), EncoderInterface::supportsEncoding()
-
removed NormalizableInterface::denormalize(), NormalizerInterface::denormalize(), NormalizerInterface::supportsDenormalization()
-
removed normalize() denormalize() encode() decode() supportsSerialization() supportsDeserialization() supportsEncoding() supportsDecoding() getEncoder() from SerializerInterface
-
Serializer now implements NormalizerInterface, DenormalizerInterface, EncoderInterface, DecoderInterface in addition to SerializerInterface
-
added DenormalizableInterface and DenormalizerInterface
-
[BC BREAK] changed
GetSetMethodNormalizer
's key names from all lowercased to camelCased (e.g.mypropertyvalue
tomyPropertyValue
) -
[BC BREAK] convert the
item
XML tag to an array<?xml version="1.0"?> <response> <item><title><![CDATA[title1]]></title></item><item><title><![CDATA[title2]]></title></item> </response>
Before:
Array()
After:
Array( [item] => Array( [0] => Array( [title] => title1 ) [1] => Array( [title] => title2 ) ) )