Nested CBLJSONencoding example

110 views
Skip to first unread message

Abhishek Srivastava

unread,
Jul 2, 2015, 1:18:13 PM7/2/15
to mobile-c...@googlegroups.com
Hello,

I am designing an application where there are three classes.

class A derived by CBLJSONEncoding and implementing protocol
class B also derived by CBLJSONEncoding and also keeping NSArray of class A.
class C derived by CBLModel class and keeping the NSArray of class B.

class A: CBLJSONEncoding
{

}

class B: CBLJSONEncoding
{

NSArray *arrayOfA; -- here only addresses of A comes
};

class C: CBLModel
{

NSArray * arrayofB; - this gets encoded properly
}

When I am saving the object. the encoded Json seems to work fine till the level of class C and class B.
But the class A is not being encoded and instead only address of Class A are coming within Class B.

Could you please guide how to hold the CBLJSONEncoding class within CBLJSONEncoding dervied class?

I am also not able to find proper example of NestedModeling. On how to use

(Class)nsarrayitem{ return [NSArrayItemClassl class]; }
Kindly guide.

Thanks
Abhishek

Jens Alfke

unread,
Jul 2, 2015, 1:36:03 PM7/2/15
to mobile-c...@googlegroups.com

On Jul 2, 2015, at 10:12 AM, Abhishek Srivastava <sr.ab...@gmail.com> wrote:

Could you please guide how to hold the CBLJSONEncoding class within CBLJSONEncoding dervied class?

An instance of CBLJSONEncoding is entirely responsible for creating its own JSON encoding — CBLJSONEncoding is just a protocol, so it can’t help you with the implementation at all.

If your implementation contains other objects that implement CBLJSONEncoding, you’ll have to encode those objects yourself as part of the result you return, probably by calling their -encodeAsJSON methods and incorporating the result.

I am also not able to find proper example of NestedModeling. On how to use
(Class)nsarrayitem{ return [NSArrayItemClassl class]; }

I’m not sure what you mean by that. Do you mean declaring the element types in array properties?
Models don’t really nest; they just contain JSON data. Maybe you’re referring to relationships between models, i.e. a property whose value type is a model class or an array of models?

—Jens
Reply all
Reply to author
Forward
0 new messages