Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- New interface `Redmine\Http\HttpClient` for new minimalistic HTTP clients.
- New interface `Redmine\Http\Request` for sending data with new minimalistic HTTP clients.
- New method `Redmine\Api\...::getLastResponse()` to get the last response made by the API class.
- Add support for custom arrays in `Redmine\Serializer\XmlSerializer`

### Changed

Expand Down
6 changes: 6 additions & 0 deletions src/Redmine/Serializer/XmlSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@ private function addChildToXmlElement(SimpleXMLElement $xml, $k, $v): void
foreach ($v as $id) {
$array->addChild($specialParams[$k], $id);
}
} elseif (is_array($v)) {
$array = $xml->addChild($k, '');
$array->addAttribute('type', 'array');
foreach ($v as $id) {
$array->addChild($k, $id);
}
} else {
$xml->$k = $v;
}
Expand Down
19 changes: 19 additions & 0 deletions tests/Unit/Serializer/XmlSerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,25 @@ public static function getNormalizedToEncodedData(): array
</issue>
XML,
],
'test with custom array' => [
[
'issue' => [
'taglist' => [
'approved',
'finished',
],
],
],
<<< XML
<?xml version="1.0"?>
<issue>
<taglist type="array">
<taglist>approved</taglist>
<taglist>finished</taglist>
</taglist>
</issue>
XML,
],
'test with ignored elements' => [
[
'issue' => [
Expand Down