I collect some data in xml format through an API and would like to deserialize it in an objects list. I'm using Symfony2 and find out JMSSerializerBundle but I do not really know how to use it.
I know that Sf2 allows to serialize/deserialize object to/from array, but I'm looking for something more specific. For example, for this class :
class Screenshot
{
/**
* @var integer $id
*/
private $id;
/**
* @var string $url_screenshot
*/
private $url_screenshot;
public function __construct($id, $url_screenshot) {
$this->id = $id;
$this->url_screenshot = $url_screenshot;
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set url_screenshot
*
* @param string $urlScreenshot
*/
public function setUrlScreenshot($urlScreenshot)
{
$this->url_screenshot = $urlScreenshot;
}
/**
* Get url_screenshot
*
* @return string
*/
public function getUrlScreenshot()
{
return $this->url_screenshot;
}
/**
* Serializes the Screenshot object.
*
* @return string
*/
public function serialize()
{
return serialize(array(
$this->id,
$this->url_screenshot
));
}
/**
* Unserializes the Screenshot object.
*
* @param string $serialized
*/
public function unserialize($serialized)
{
list(
$this->id,
$this->url_screenshot
) = unserialize($serialized);
}
public function __toString() {
return "id: ".$this->id
."screenshot: ".$this->url_screenshot;
}
}
I would like serializing/deserializing to/from this kind of xml :
<?xml version="1.0" encoding="UTF-8" ?>
<screenshots>
<screenshot>
<id>1</id>
<url_screenshot>screenshot_url1</url_screenshot>
</screenshot>
<screenshot>
<id>2</id>
<url_screenshot>screenshot_url2</url_screenshot>
</screenshot>
<screenshot>
<id>3</id>
<url_screenshot>screenshot_url3</url_screenshot>
</screenshot>
</screenshots>
I really want to use something integrated/to integrate in Sf2 (something "smooth") and prefer avoiding any homemade xml parsers.