Skip to content

Instantly share code, notes, and snippets.

@mathiasverraes
Created February 7, 2013 12:24
Show Gist options
  • Save mathiasverraes/4730589 to your computer and use it in GitHub Desktop.
Save mathiasverraes/4730589 to your computer and use it in GitHub Desktop.
<?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
@mathiasverraes
Copy link
Author

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.

@mathiasverraes
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment