Hi dev@,

There has been some recent discussion around the usage of AutoValue [1] in 
jclouds. Over the past couple of days, I have been prototyping with it in the 
OpenStack Heat API.  I realize that this is far from being complete, however I 
am pretty excited about it and wanted to share what I have been able to 
accomplish so far.

To start, I wasn’t quite sure how to integrate Gson and AutoValue, but luckily 
I found this Gist [2]. Thanks Jake!

I was able to get the prototype up and running with some fairly trivial changes 
using the above Gist code:

in jclouds/core:
- Added the `AutoGson` class to `org.jclouds.rest.annotations` package
- Added the `AutoValueTypeAdapterFactory` class to `org.jclouds.json.internal`
- Register the above `TypeAdapterFactory` in 
`org.jclouds.json.config.GsonModule`

In jclouds-labs-openstack/openstack-heat:
- Created a simple `AutoStack` class with AutoValue/AutoGson annotations and 
provided necessary methods.
- Added a test to the `StackApiMockTest` to test parsing of the JSON.

The good news is that the test ran successfully through the jclouds codebase.  
I ran into some weirdness with the mapping of the snakey case method names to 
non-snakey case field names. We usually annotate the fields using @Named, but 
how do you do that?  Hmm… More investigation necessary.

As it stands, I was only able to get it to map the JSON correctly using janky 
looking snaky-methods due to the way it generates the code. I am currently 
blocked because of this, so if anyone has insight here, please share.

Check out this gist [3] if you are interested in this WIP, thanks!

/jd

[1] https://github.com/google/auto/tree/master/value
[2] https://gist.github.com/JakeWharton/0d67d01badcee0ae7bc9
[3] https://gist.github.com/jdaggett/11c746ccb257842d5cb5

Reply via email to