Hey folks,

somebody tested the new Serialization API described on http://drupal.org/node/1899138 and had a simple example? I like to test the xml serialization of Drupal8.
In the end i want to realize a former Drupal6 Xml output, which was created with drupal_set_header() and XmlWriter, with Drupal8.

I just tried a simple function which is called by hook_menu(), but i think it have to be structured different

function mymodule_serialize() {
   $serializer = $this->container->get('serializer');
   $output = $serializer->serialize('Hello', 'json');
   return $output;
}

Can somebody post a simple example?
Thanks a lot.

Comments

tobkab’s picture

I can load it with

$serializer = drupal_container()->get('serializer');

And when i get a node by node_load() and pass it to serialize() i got and error for XML:
Serialization for the format xml is not supported in Symfony\Component\Serializer\Serializer->serialize()

and for JSON:
Objects returned by Drupal\node\Plugin\Core\Entity\Node::getIterator() must be traversable or implement interface Iterator in Drupal\Core\Serialization\ComplexDataNormalizer::normalize()

I also found the EntityInterface where is written :
When implementing this interface which extends Traversable, make sure to list IteratorAggregate or Iterator before this interface in the implements clause..

But i'm could not solve it right now ;-)

Anonymous’s picture

I just found this question.

I'm happy to hear there is someone who wants to test this out. In general, if you have questions you'll want to post them to the WSCCI group (http://groups.drupal.org/wscci), the core issue queue (marking serialization.module as the component), or ask in the #drupal-wscci IRC channel.

Serialization only works for EntityNG entities... that's the new version of the Entity API. Node was converted a few weeks ago, so it should be working. I haven't tested it though, so if you want to test it and report on results, that would be great :)