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

Make automatic conversion between underscores and camelCase optional #62

Open
balazsgerlei opened this issue Nov 6, 2016 · 4 comments

Comments

@balazsgerlei
Copy link

You added automatic conversion from underscores to camelCase in 2.1 (#31), which is great but I think it would be better if it is optional.

I mean, if a property with underscore case found, parse the json node to that, and only try to parse to a camelCase one if a parameter with the exact same underscore case-d name not found.

@balazsgerlei
Copy link
Author

Any thoughts on this @aryaxt ?

@aryaxt
Copy link
Owner

aryaxt commented Jan 20, 2017

hey @balazsgerlei sorry haven't had time to look into the repos for a while. Can you please explain the problem. I'm having a problem understanding what the problem is to have this logic automated. Thanks

@balazsgerlei
Copy link
Author

Hi,
Sure I'll try to explain it better. In my experience with this lib (I use it in Swift), since version 2.1, I can parse properties from json which are in underscore_case (ex. "some_property") to properties in my model objects that are using camelCase (ex. someProperty). But I can no longer parse into model objects that use properties with underscore_case (ex. "some_property"). I think the apropriate behaviour should be that the lib always try to parse into properties with the same casing, but if that is not found, it also tries converting to camelCase. So if I receive a json with underscore case properties and I have a model class with also underscore_cased properties, it can parse it, but I can also parse the same json to a model class with camelCased properties. This is basically how the awesome Gson parse-ing library works in Java (https://github.com/google/gson).

This issue really comes into play when I communicate with a server (via Json) which sends AND accepts Json with properties with underscore_cased properties. And with the current version of this lib I can only communicate with this server if I have two separate class of every model objects: one for each direction. This is because if I use camelCase in my class, the lib correctly parses received JSON into it, but it is converted to a JSON with camelCase properties when I try to send data back to the server. So to solve this problem, I suggest either this (what I detailed now in this issue) or a solution to the other issue that I created:
#61

That other issue suggests that automatic conversion to underscore_cased Json properties should be somehow achievable with library (so to be able to create a Json with undescore_cased properties from a class with camelCased properties).

Ideally it would be the best solution to enable both and parse like I detailed in this issue, whole providing a way to choose between how properties are written to Json (either with the same casing or converted from camelCase to underscore_case).

@lorenzoPrimi
Copy link

I had to force the 2.0 version on my app to make it work, waiting for a fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants