realm-java icon indicating copy to clipboard operation
realm-java copied to clipboard

RealmList<Integer / String / ...>

Open an-k opened this issue 12 years ago • 139 comments

Dear realm-Team,

I'm really impressed by Realm and I do like the way you're providing support and solutions on github, SO and gGroups! I like working with Realm - however there are three really big drawbacks for me:

  1. No model-instantiation by = new ... - I know you're on it. I can't wait for this! Do we have to wait for the "whole" JSON-Upgrade or will there be an earlier release providing this feature?

  2. No model-passing across threads. That's hindering all the great benefits of EventBus and Android Priority Job Queue. But I read that it will be possible in the further versions and I'm looking forward on this.

  3. The reason for this issue: In my model class I'm allowed to have primitive fields as well as object fields of objects that extend RealmObject. But I'm not allowed to have a field type like RealmList<Integer> or RealmList<String>. However it is possible to work around this by

RealmList<RealmString> names;

and

public class RealmString extends RealmObject {
private String name;
// getter & setter

It works but it's really ugly and should be unnecessary in my opinion. Is there any improvement planned regarding this?

Thanks again for your great work - I'm glad Realm helps me developing my app!


Related PRs:

  • [ ] API design (#4165)
  • [ ] Implementation (#5031)

an-k avatar Nov 18 '14 02:11 an-k

I had bit of worries about the Realm design but after using it a lot i have seen it is done just right. My primary use of Realm is to pass data between threads (background processing and UI) and it works perfectly. It is so fast that even AsyncTasks are not needed anymore. Great work. Just few bugs left but easy to work around while waiting for the completion. I hope the next release comes out soon.

codezion avatar Nov 18 '14 04:11 codezion

@an-k I think that your suggestion (RealmList<String> etc.) is a good one. The complexity of implementing it is "less than impossible" but "greater than trivial". In particular the querying these lists of primitive types could be a bit tricky.

To make a long story short, I can give you a time frame in which it will be implemented.

kneth avatar Nov 18 '14 15:11 kneth

@kneth Thanks for your reply! You can give a time frame? That's great, so when will that probably be?

an-k avatar Nov 18 '14 18:11 an-k

@an-k Sorry for being unclear (I forgot a "not"); we don't have any time frame as we haven't decided if we wish to support it.

kneth avatar Nov 19 '14 07:11 kneth

@kneth This issue is the major reason for not using it in production yet, I can't change my JSON input, so to use it, I would have to do some really ugly tricks. And with issues #489 and now #682 rising, I think it should be considered worth supporting.

For my use cases, if it got serialized as a string in the database and back as List, without any type of in db querying (no need to limit, search, just retrieve all), would be perfect.

I think that should be added some kind of RealmPrimitive class or an @ElementCollection annotation like the JPA 2 has.

Hazer avatar Dec 23 '14 23:12 Hazer

Can I ask what the current state and/or priority of this feature request is? Or: What is the recommended workaround for now?

jenzz avatar Feb 07 '15 16:02 jenzz

I agree that this is a worthwhile feature. +1.

mpost avatar Feb 08 '15 16:02 mpost

Yes, please

ghost avatar Feb 11 '15 09:02 ghost

+1

kboyarshinov avatar Feb 12 '15 06:02 kboyarshinov

Would help solve issues like http://stackoverflow.com/questions/28733024/gson-deserialization-of-liststring-into-realmlistrealmstring +1

kaushikmukunda avatar Feb 26 '15 01:02 kaushikmukunda

+1

Not only primitive datatypes should be mentioned. Enums should be set in a list too.

FHellmann avatar Mar 07 '15 14:03 FHellmann

+1 for the List of primitive and also +1 for the Enums. I'm actually kinda stuck now as I have a JSON with a list of strings that needs to go to the DB, not quite sure yet how to deal with that.

theyann avatar Mar 18 '15 20:03 theyann

+1

RobertoArtiles avatar Mar 30 '15 21:03 RobertoArtiles

+1

kbpontius avatar Apr 17 '15 20:04 kbpontius

+1

jmxt3 avatar Apr 24 '15 22:04 jmxt3

+1

marianmoldovan avatar Apr 27 '15 21:04 marianmoldovan

+1

theostanton avatar Apr 30 '15 13:04 theostanton

+1

eygraber avatar May 01 '15 18:05 eygraber

A list of Strings is a very common use case for JSON responses. When you are given an array of Strings such as

"phoneNumbers":["000-000-0000", "111-111-1111"]

and you need to store it in the database, you need a list of Strings.

Implementing a workaround for every instance of a JSONArray of Strings would be bloated and ugly, unless I'm not understanding the workaround correctly. Can I create a RealmString once and use it in place of String everywhere that I would need a RealmList of Strings? How would I get RetroFit (REST library from Square) to play nice with such an implementation?

In any case, having this issue resolved would simplify the code and it seems that many people are looking for the same feature. Perhaps the priority of this feature should be increased over something else.

harish1312 avatar May 12 '15 01:05 harish1312

@harish1312 In the documentation (http://realm.io/docs/java/latest/#other-libraries) you can read on how to use Realm with RetroFit and GSON.

kneth avatar May 13 '15 08:05 kneth