tebru / gson-php

Gson implemented in PHP
Other
151 stars 18 forks source link

Weird Capitalization error #9

Closed Samistine closed 6 years ago

Samistine commented 6 years ago

So I can't seem to get it to deserialize variables that have capital letters in them without specifying the SerializedName annotation.

The following does not work.

/**
 * @var integer
 */
public $testTest;
natebrunette commented 6 years ago

@Samistine By default, this will get serialized as test_test. Add your own naming strategy to override this behavior. Your implementation would just return the given name.

https://github.com/tebru/gson-php/blob/master/docs/Advanced.md#add-property-naming-strategy

Samistine commented 6 years ago

Thanks, I don't think the java gson implementation works this way so I was confused

natebrunette commented 6 years ago

That was done because the common serializer in PHP converts the field names to snake case. I will consider adding support to the builder to allow passing in a value that will define the common strategies google/gson supports.

natebrunette commented 6 years ago

@Samistine This can be done more similarly to gson now

https://github.com/tebru/gson-php/blob/master/docs/Advanced.md#change-property-naming