Skip to content

[Serializer] Context Options on how numeric/float are normalized to XML #58429

Open
@Hanmac

Description

@Hanmac

Description

Currently scalar numeric values are passed directly to the Encoders

which is then formatted into string:

} elseif (is_numeric($val)) {
return $this->appendText($node, (string) $val);

for the xml i am working on, i would like to have the floating points fixed, so it can be serialized into:

<element>12.50</element>

instead of this:

<element>12.5</element>

my current tests for my library using Serializer does read the XML into Objects and writes them back into XML again and compares the XML-Strings. These differences currently make the Tests fail.

because this might depend on the properties, it might need to be done in AbstractObjectNormalizer too:

if (null === $attributeValue || \is_scalar($attributeValue)) {
$data = $this->updateData($data, $attribute, $attributeValue, $class, $format, $attributeContext, $attributesMetadata, $classMetadata);
continue;

The ScalarNormalizer might need to be format specific, like it should only do Numeric to FormatString for XML, not for JSON

Related to #58305 and #58056

Example

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions