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

Use of camelCased properties importing from JSON #1063

Closed
michalkos opened this issue Oct 22, 2014 · 5 comments
Closed

Use of camelCased properties importing from JSON #1063

michalkos opened this issue Oct 22, 2014 · 5 comments

Comments

@michalkos
Copy link

My model in Swift has property named isPromo.
In JSON, this property is named is_promo and this throws an exception when importing with createInDefaultRealmWithObject

Is there some way how to import this without changing the JSON dictionary?
It would be nice to have some function in model where we could define this transforms. Also if we have different property names in models.

For example something like this:

class MyModel: RLMObject {
    dynamic var isPromo = false
    dynamic var productDescription = ""

    override class func importPropertyNames() -> [String : String] {
        return [ "is_promo" : "isPromo", "description" : "productDescription" ]
    }
@yoshyosh
Copy link
Contributor

Hi Michal I believe you need to have to exact names in your model and JSON response to map them with the createInDefaultRealmWithObject method. We are actively working on a way to make this much easier. For now using something like https://github.com/Mantle/Mantle is recommended to remap any property names and types. Then passing the mantleObject to the createInDefaultRealmWithObject method

@yoshyosh
Copy link
Contributor

Here is a library that someone in the community made that does just this https://github.com/matthewcheok/Realm-JSON

We are working on something similar in the near future

@alazier alazier added the backlog label Dec 5, 2014
@pizthewiz
Copy link
Contributor

Another option for those in need, ObjectMapper which is Mantle-like in that it allows serialization to and from JSON and has property transformers, but perhaps a bit more lean.

@yoshyosh
Copy link
Contributor

yoshyosh commented Apr 8, 2015

Incase someone else comes across this, another person had issues using ObjectMapper #1726

@timanglade
Copy link
Contributor

Closing as duplicate of #694

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants