[aerogear-dev] JSON Serialization in Android

Marko Strukelj marko.strukelj at gmail.com
Mon Nov 5 07:13:45 EST 2012


On Fri, Nov 2, 2012 at 3:51 PM, Summers Pittman <supittma at redhat.com> wrote:

> Right now we have JSON serialization in Android implemented by a default
> configuration GSON instance.
>
> I am updating the docs to note this, however it is "only" an
> implementation detail.
>
> 1) Do we want to say for 1.x that GSON IS the library we are using?  (Yes)

+1


> 2) Do we want to provide a configuration point for Serialization (GSON if
> yes to 1, something more general if No)? (Yes, but not for 1.0)
>
Yes, I think we should provide pluggability. Maybe even for 1.0 as it seems
fairly easy.

This would cover our current serialization needs:

public interface Marshaller<T> {
   void String marshal(T obj) throws IOException;
   void List<T> unmarshal(String json) throws IOException;
}

With Builder pattern you could specify Marshaller at Pipe creation time
i.e.:

new Pipe.Builder().useMarshaller(Pipe.DEFAULT_MARSHALLER)
    .name("tasks")
    .useClass(Task.class).build().

Where Pipe.DEFAULT_MARSHALLER ==
"org.aerogear.android.serialization.impl.GSONMarshaller";

User has no compile-time dependency on impl detail, and has the ability to
plug in something of her own.

(I noticed Builder vs. Configuration object debate. Will comment more
there.)


2.1) How much do we want to expose/allow to be configured? (No idea)
>
>
The above pattern doesn't account for any configuration. System properties
could be used (ugly). But it can be changed - use MarshallerFactory object
instead of Marshaller class name:

public interface MarshallerFactory {

   Marshaller newMarshaller();
}

new Pipe.Builder().useMarshallerFactory(new
org.aerogear.android.serialization.GSONMarshallerFactory())
    .name("tasks")
    .build();

This time GSONMarshallerFactory is part of an API. And user can create any
implementation of MarshallerFactory and use it to create and configure a
custom Marshaller.


I think pluggability would be really good to have for version 1.0 already.
As it influences the builder / factory patterns. It's the only way to make
sure the patterns we use really are pluggable otherwise we may very quickly
have to deprecate some of 1.0 API.

Besides Serialization one aspect of pluggability could be Transport i.e.
plug in HttpURLConnection instead of HttpClient.


- marko


Relevant Jira:https://issues.jboss.org/browse/AEROGEAR-596
>
> Summers
> _______________________________________________
> aerogear-dev mailing list
> aerogear-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/aerogear-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/aerogear-dev/attachments/20121105/d48e2763/attachment.html 


More information about the aerogear-dev mailing list