liip / serializer

A PHP serializer that generates PHP code for maximum performance
MIT License
128 stars 10 forks source link

CAMELCASE #27

Open victorgp89 opened 2 years ago

victorgp89 commented 2 years ago

Hi, Congrats for the project, is posible to avoid camelcase in metadata construction? Thanks for advance

dbu commented 2 years ago

hi, thanks. i think you could use the @JMS\SerializedName annotation, but that would mean having to annotate every property of every model, so its more a hack than a proper solution.

i think the correct way would be to have a strategy pattern to change the serialized name on the property metadata. i don't have the time right now to look into it, but if you are interested in this, it should happen in https://github.com/liip/metadata-parser/ somewhere. i am not sure if we can reasonably do it while building the metadata tree, or if we should transform the final tree into a new tree with different serialized name properties. or if it would be correct to make the serialized name of PropertyMetadata mutable.

dbu commented 1 year ago

@Spea added identical naming in https://github.com/liip/metadata-parser/pull/28 but with only a flag. to add camelCase support, we would need to refactor this to a proper naming strategy pattern. linking the pull request here as it indicates the places where the metadata parser needs to be adjusted to change naming strategies.