-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from Dropelikeit/bugfix/wrong-headers
Fix: Wrong headers on xml added at serialization
- Loading branch information
Showing
2 changed files
with
42 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,9 +7,11 @@ | |
use Dropelikeit\LaravelJmsSerializer\Config\Config; | ||
use Dropelikeit\LaravelJmsSerializer\Config\ConfigInterface; | ||
use Dropelikeit\LaravelJmsSerializer\Exception\SerializeType; | ||
use Illuminate\Http\Response as LaravelResponse; | ||
use JMS\Serializer\SerializationContext; | ||
use JMS\Serializer\SerializerInterface; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
/** | ||
* @author Marcel Strahl <[email protected]> | ||
|
@@ -70,7 +72,7 @@ public function withSerializeType(string $serializeType): self | |
return $instance; | ||
} | ||
|
||
public function create(object $jmsResponse): JsonResponse | ||
public function create(object $jmsResponse): Response | ||
{ | ||
$initialType = $this->getInitialType($jmsResponse); | ||
|
||
|
@@ -81,19 +83,27 @@ public function create(object $jmsResponse): JsonResponse | |
$initialType | ||
); | ||
|
||
return new JsonResponse($content, $this->status, ['application/json'], true); | ||
if ($this->serializeType === Config::SERIALIZE_TYPE_XML) { | ||
return new LaravelResponse($content, $this->status, ['Content-Type' => 'application/xml']); | ||
} | ||
|
||
return new JsonResponse($content, $this->status, ['Content-Type' => 'application/json'], true); | ||
} | ||
|
||
/** | ||
* @param array<int|string, mixed> $jmsResponse | ||
* | ||
* @return JsonResponse | ||
* @return Response | ||
*/ | ||
public function createFromArray(array $jmsResponse): JsonResponse | ||
public function createFromArray(array $jmsResponse): Response | ||
{ | ||
$content = $this->serializer->serialize($jmsResponse, $this->serializeType, $this->context); | ||
|
||
return new JsonResponse($content, $this->status, ['application/json'], true); | ||
if ($this->serializeType === Config::SERIALIZE_TYPE_XML) { | ||
return new LaravelResponse($content, $this->status, ['Content-Type' => 'application/xml']); | ||
} | ||
|
||
return new JsonResponse($content, $this->status, ['Content-Type' => 'application/json'], true); | ||
} | ||
|
||
private function getInitialType(object $jmsResponse): ?string | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters