Support custom model mappings #694

Closed
c0rrzin opened this Issue Jul 28, 2014 · 13 comments

Projects

None yet

10 participants

@c0rrzin
c0rrzin commented Jul 28, 2014

I know it's in your pipeline, but I'd like to start scratching some code, because I really need it to my Project.

FYI: I already submitted a registration to your CLA.

@alazier alazier added the backlog label Dec 5, 2014
@eni9889
eni9889 commented Dec 6, 2014

+1 on this please

@timanglade timanglade added P2 and removed backlog labels Apr 22, 2015
@bdash bdash changed the title from Add JSON<->RMLObject (and RMLArray) Serializers to Add JSON<->RLMObject (and RLMArray) Serializers Sep 2, 2015
@jpsim jpsim changed the title from Add JSON<->RLMObject (and RLMArray) Serializers to Support custom model mappings Oct 1, 2015
@jpsim
Member
jpsim commented Oct 1, 2015

We discussed this at our company all-hands week earlier this month and determined that given the wealth of available model mapping libraries, many of which are well built and actively maintained, that we won't be building model-mapping functionality into Realm itself for the foreseeable future.

Here are a few libraries you can use to do this:

Objective-C

Swift

There are many other libraries to choose from. We hope that by investing in properly supporting these 3rd party model mapping solutions, we can focus on building features only Realm can do, while supporting these great community projects.

@jpsim jpsim added backlog Feature and removed Enhancement P2 labels Oct 1, 2015
@kylebshr
kylebshr commented Oct 1, 2015

Thanks for pointing those out — they seem like great options. I was hoping to be able to just throw dictionaries from my json into Objects init, but this feels like the better way to do it.

Edit: the Argo link is broken if you'd like to fix that :)

@kylebshr
kylebshr commented Oct 1, 2015

I'm having trouble implementing Decodable with Realm — @jpsim, do you have any experience with it, or an example?

@jpsim
Member
jpsim commented Oct 1, 2015

Edit: the Argo link is broken if you'd like to fix that :)

Thanks, fixed.

I'm having trouble implementing Decodable with Realm — @jpsim, do you have any experience with it, or an example?

There are a number of examples on that project's README. If you're still having trouble implementing that, please file a new issue outlining exactly what you're doing and how it's not working. Either on this repo, or Decodable's, as you deem appropriate.

@Payload-Lee

+1

@marksbren

Has anyone found a model framework that allows for Realm Notifications and works with RealmSwift? I tried ObjectMapper, but mapping objects to JSON must be done in a Realm write block (the "inout" flag issue), which triggers the Realm Notification and falls into a infinite loop (mapping to JSON triggers a notification which triggers a mapping to JSON, etc.)

@jpsim
Member
jpsim commented Dec 10, 2015

@marksbren did you read my comment in #694 (comment)? Argo & Decodable work great with Realm.

@marksbren

@jpsim thanks for the quick reply. I will try Decodable and report back

@kylebshr

Also — Mapper from Lyft is a great new one, I switched from Decodable and definitely like it more. All of these libraries have a few caveats to get them working with classes instead of structs though, due to Swift bugs.

@jpsim
Member
jpsim commented Mar 28, 2016

Based on the comments here about the already thriving set of third party mapping frameworks, and keeping Realm composable, we've determined that it's out of scope for Realm do perform model mapping.

@jpsim jpsim closed this Mar 28, 2016
@jpsim jpsim removed the S:Idea Backlog label Mar 28, 2016
@JinkProject
JinkProject commented Nov 23, 2016 edited

@jpsim Am I seeing things, or does Realm support this now? Using initWithValue or createOrUpdateWithValue and passing it a dictionary seems to do the trick for me with no problems so far... I know it isn't as flexible as using Mantle or JSONModel, but bare-bones parsing of a single object seems to work fine.

@jpsim
Member
jpsim commented Nov 23, 2016 edited

Realm has supported that since the launch of the Objective-C framework over two years ago.

What this issue was tracking was mapping models, e.g. if the untyped dictionary input had key names that didn't match property names, or value types that didn't match property types, etc.

We ended up closing this issue so we can focus on building great database features considering the great libraries that are out there that already focus on doing model mapping.

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