couchbase / couchbase-lite-android-ce

The community edition of couchbase lite for android
Apache License 2.0
9 stars 1 forks source link

Please make `DictionaryInterface` interface public #8

Closed AlBlanc closed 5 years ago

AlBlanc commented 7 years ago

Hello CB team,

I am writing an ORM for couchbase lite 2.0 and i am getting stuck. I need DictionaryInterface to be public to make a common flow usable for Document and Dictionnary (for nested object)

Thank you!

hideki commented 7 years ago

Hi @AlBlanc, We intentionally make DictionaryInterface nonpublic. It forces the implementation class to have the declared methods. Thanks, Hideki

AlBlanc commented 7 years ago

Ok. Then would have been great to have Document inherit from Dictionary (but looks more complicated) or even a getter for Document.dictionary private field.

I am just looking for a way to avoid duplicate code because i treat them equally during the serialization process of my ORM (eg: nested documents -> nested classes). But I'll copy/paste it if there is no other way.

AlBlanc commented 7 years ago

Nevermind, I went deeper into the project and I may found something. I think i'll work with the method public Dictionary set(Map<String, Object> dictionary) and copy the static method CBLData.convert(Object valut)

mswokk commented 6 years ago

@hideki I have the same problem with @AlBlanc Due to the DictionaryInterface is not public, I have to write unmarshalling code for Result and Document twice. Hard to manage.

Is there any workaround or trick to do not make the duplicated code? Or is there any special reason for DictionaryInterface is non-public? Forcing classes to implement methods cannot be a reason for not-public

AlBlanc commented 6 years ago

Hi @mswokk,

Actually I have just finished to rewrite completely my "Document mapper" (I can't say ORM for the moment yet) in kotlin, and I have done it without needed these interfaces.

If you want to have a look -> https://github.com/Sportner/CBLMapper

You can register custom types, it handles enums, arrays (use Arralist and HashMap as default list/map). It still under construction but works pretty well. :)

AlBlanc commented 6 years ago

Actually, Sorry @mswokk I replied too quickly, I am facing exactly the same issue as you.

I still don't see the point to make DictionnaryInterface not public... It would help us to build products on top of it...

FYI you can have a look at how I did to have as less duplicate code as possible -> https://github.com/Sportner/CBLMapper/blob/master/cblmapper/src/main/java/io/sportner/cblmapper/CBLMapper.kt#L91

pasin commented 6 years ago

CBL iOS (Objective-C) and .NET have DictionaryInterface public. We probably should do the in CBL Android.

mswokk commented 6 years ago

@pasin Please consider ArrayInterface too.

pasin commented 6 years ago

Absolutely.

mswokk commented 6 years ago

@AlBlanc Thank you for answer. If you are hurrying up, please check my workaround.

I created Kotlin extension function for each classes which implements DictionaryInterface, ArrayInterface. Although my codes are duplicated, once you import it, you can use it everywhere in your own document.

bmeike commented 5 years ago

Opened https://issues.couchbase.com/browse/CBL-32 to track this. Please follow it there.

bmeike commented 5 years ago

Fixed in couchbase-lite-java:26e89439318531d05