Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bug with custom type handlers and strings - #384 #202 #180 #458

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 4 additions & 0 deletions src/JMS/Serializer/GraphNavigator.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use JMS\Serializer\Handler\HandlerRegistryInterface;
use JMS\Serializer\EventDispatcher\EventDispatcherInterface;
use JMS\Serializer\Metadata\ClassMetadata;
use JMS\Serializer\Util\String;
use Metadata\MetadataFactoryInterface;
use JMS\Serializer\Exception\InvalidArgumentException;

Expand Down Expand Up @@ -140,6 +141,9 @@ public function accept($data, array $type = null, Context $context)
// TODO: The rest of this method needs some refactoring.
if ($context instanceof SerializationContext) {
if (null !== $data) {
if(is_string($data)) {
$data = new String($data);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use 4 space (no tab) for indentation

if ($context->isVisiting($data)) {
return null;
}
Expand Down
32 changes: 32 additions & 0 deletions src/JMS/Serializer/Util/String.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace JMS\Serializer\Util;

/**
* Class String
* @package JMS\Serializer\Util
* @author Bubelbub <[email protected]>
*/
class String
{
/**
* @var string
*/
private $content = null;

/**
* @param string $content
*/
public function __construct($content)
{
$this->content = $content;
}

/**
* @return string
*/
public function __toString()
{
return $this->content;
}
}