Handle xsd:anyType and xsd:anySimpleType with custom handlers
masterIf your XSD contains xsd:anyType or xsd:anySimpleType, you must map these to custom handlers in your config.yml using the aliases key. You then implement a class that implements SubscribingHandlerInterface to define how serialization and deserialization should behave for these types.
# config.yml
xsd2php:
aliases:
'http://www.w3.org/2001/XMLSchema':
anyType: 'MyCustomAnyTypeHandler'
anySimpleType: 'MyCustomAnySimpleTypeHandler'use JMS\\Serializer\\Handler\\SubscribingHandlerInterface;
use JMS\\Serializer\\GraphNavigator;
class MyHandler implements SubscribingHandlerInterface
{
public static function getSubscribingMethods()
{
return [
[
'direction' => GraphNavigator::DIRECTION_DESERIALIZATION,
'format' => 'xml',
'type' => 'MyCustomAnyTypeHandler',
'method' => 'deserializeAnyType'
],
[
'direction' => GraphNavigator::DIRECTION_SERIALIZATION,
'format' => 'xml',
'type' => 'MyCustomAnyTypeHandler',
'method' => 'serializeAnyType'
]
];
}
public function serializeAnyType($visitor, $data, array $type, $context)
{
// implementation
}
public function deserializeAnyType($visitor, $data, array $type)
{
// implementation
}
}