anyone know a quick way to bind guava Optional<X> to gson?

226 views
Skip to first unread message

Adrian Cole

unread,
Apr 24, 2012, 7:28:22 PM4/24/12
to jclou...@googlegroups.com
Hey, guys.

There are cases where we know that some things are going to be
Nullable. Since few read annotations personally, seems ideal to just
swap out @Nullable for Optional<X> (at least in fields). Does anyone
have an idea how to write a gson type adapter for this?

-A

Andrew Phillips

unread,
Apr 24, 2012, 9:44:05 PM4/24/12
to jclou...@googlegroups.com

Are we happy with the fact that replacing the annotation with Optional
means that code will break because the fields now have new types?

ap

Adrian Cole

unread,
Apr 24, 2012, 9:47:42 PM4/24/12
to jclou...@googlegroups.com
via Jesse, who probably bounced:

"It should be relatively easy to write a TypeAdapterFactory[1] that
does it. You'll need to unpack the optional and delegate to the type
adapter of the adapted value."

also inline :)

-A

[1] https://google-gson.googlecode.com/svn/trunk/gson/docs/javadocs/com/google/gson/TypeAdapterFactory.html
well, I'm talking about new code :)
>
> ap
>
> --
> You received this message because you are subscribed to the Google Groups
> "jclouds-dev" group.
> To post to this group, send email to jclou...@googlegroups.com.
> To unsubscribe from this group, send email to
> jclouds-dev...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/jclouds-dev?hl=en.
>
Reply all
Reply to author
Forward
0 new messages