Hi Guofeng,

Couchbase Lite for Android/Java uses Jackson (http://jackson.codehaus.org) 
to parse and serialize JSON.

To serialize Java object to JSON, CBL calls byte[] 
ObjectMapper.writeValueAsByte(Object value)
http://jackson.codehaus.org/1.6.2/javadoc/org/codehaus/jackson/map/ObjectMapper.html#writeValueAsBytes(java.lang.Object)

>From JSON to Object, CBL calls <T> ObjectMapper.readValue(InputStream src, 
Class<T> valueType);
http://jackson.codehaus.org/1.6.2/javadoc/org/codehaus/jackson/map/ObjectMapper.html#readValue(java.io.InputStream,
 
java.lang.Class)

For serializing Java object to JSON, I believe Jackson can serialize your 
User or Address class objects to JSON. 
For parsing JSON, as CBL calls ObjectMapper.readValue() with specifying 
Map.class as valueType. It is not able to return User or Address class 
objects. However I believe Jackson returns  nicely populated Map object.

I hope this answers to your question.

Thanks,
Hideki

On Tuesday, January 27, 2015 at 3:18:59 AM UTC-8, Guofeng Zhang wrote:
>
> Thanks for the reply. 
>
> To confirm one thing about "only types that can be converted to JSON".
>
> Suppose I have a class like:
>     public class User {
>          public String name;
>          public Address address ;
>    }
>
>   public class Address { public String line ; }
>
> The User can be converted to JSON, so I think the following should work 
> well, right?
>     User u = new User() ; 
>     // ....assign some values to the instance
>     document.putProperties( "somekey", u ) ;
>
> Thanks again.
>        
>
> On Tue, Jan 27, 2015 at 12:31 AM, Jens Alfke <[email protected] 
> <javascript:>> wrote:
>
>>
>> On Jan 26, 2015, at 1:16 AM, Guofeng Zhang <[email protected] 
>> <javascript:>> wrote:
>>
>> The map's key is String, but what type of the map's value allowed here? 
>> Could it be any complex Java class?
>>
>>
>> Documents are stored as JSON, so only types that can be converted to JSON 
>> — booleans, numbers, strings, and arrays or maps of those (maps have to 
>> have strings as keys.)
>>
>> —Jens
>>
>> PS: And JSON has a "null" value, but I don't know if Java has an object 
>> for that (it's not the same as a null pointer!)
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Couchbase Mobile" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/mobile-couchbase/12C9F656-4416-40D8-9F6D-11908BABC950%40couchbase.com
>>  
>> <https://groups.google.com/d/msgid/mobile-couchbase/12C9F656-4416-40D8-9F6D-11908BABC950%40couchbase.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mobile-couchbase/dd0d76d4-d16d-4047-92f2-f98256ecce07%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to