CSV Support
There will be a support for CSV?
Regards.
Not known until, now. But i could imagine, its a lot of work... But it is a different thing, cause a CSV is no key-value-pair.
I could imagine arrays or collections to be (de)serialized, maybe with an order property.
<?php
/**
* User: maximilian
* Date: 10/30/13
* Time: 9:59 PM
*
*/
namespace JMS\Serializer\Tests\Fixtures;
/**
* @CsvDef("text-seperator='"';field-seperator=';';charset='...'");
* Class CsvArrayWrapper
*/
class CsvArrayWrapper {
/**
* Should store all values in a simple array
* @Type("array<'string'>")
* @var array
*/
public $result;
}
or for a collection of Objects
<?php
/**
* User: maximilian
* Date: 10/30/13
* Time: 10:05 PM
*
*/
namespace JMS\Serializer\Tests\Fixtures;
/**
* @CsvDef("text-seperator='"';field-seperator=';';charset='...'");
* Class CsvArrayWrapper
*/
class CsvCollectionWrapper {
/**
* Should store all values in (for example) ArrayCollection of Objects
* @Type("ArrayCollection<JMS\Serializer\Tests\Fixtures\CsvLineObject>")
* @var array
*/
public $result;
}
with:
<?php
/**
* User: maximilian
* Date: 10/30/13
* Time: 10:08 PM
*
*/
namespace JMS\Serializer\Tests\Fixtures;
/**
* @AccessorOrder("custom", custom = {"property3", "property2",...})
* Class CsvLineObject
*/
class CsvLineObject {
/**
* @Type("string")
*/
public $property1;
/**
* @Type("DateTime")
*/
public $property2;
/**
* @Type("DateInterval")
*/
public $property3;
/**
* @Type("integer")
*/
public $property4;
}
Problem will be: charakter encoding, which causes many problems with the field-/text-seperators
except of the charset thing, this should be easier to implement, cause it is one dimension less :-)
some more ideas? wanted?
+1
:+1:
i have done it by this simple workaround: CSV -> ModelObject
at first, just convert the CSV to array, there are many solutions (i have use this lib https://github.com/jwage/easy-csv). after this, just convert it to json ...
$reader = new \EasyCSV\Reader($filename);
$modelList = $serializer->deserialize(json_encode($reader->getAll()), sprintf('array<%s>', $modelClass), 'json');
There is a PR related to this over at the Serializer repo.