Created
February 7, 2013 12:24
-
-
Save mathiasverraes/4730589 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?php | |
class Thing | |
{ | |
/** | |
* @JMS\Type("integer") | |
*/ | |
private $fooBar; | |
public function getFooBar() | |
{ | |
return $this->fooBar; | |
} | |
} | |
$json = '{"fooBar": 123}'; | |
$deserializedThing = $serializer->deserialize($json, 'Thing', 'json'); | |
assert(123, $deserializedThing->getFooBar()); | |
// FAILS, we get null instead | |
// Adding @JMS\SerializedName("fooBar") resolves the issue | |
// Internally, the serializer converts fooBar to foo_bar unless instructed otherwise |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This behavior is documented under @SerializedName http://jmsyst.com/libs/serializer/master/reference/annotations
However, this is so counterintuitive, that I think it is a bug. In the example above, there's absolutely no reason why the serializer should interfere with my naming, since both the json and the php code use camelcase.