correct order of List<Byte> gson registration and filled missing test

This commit is contained in:
adriancole 2013-03-14 09:44:28 -07:00
parent 97a76c2ab4
commit 6f9794dedb
2 changed files with 16 additions and 2 deletions

View File

@ -106,14 +106,14 @@ public class GsonModule extends AbstractModule {
// simple (type adapters)
builder.registerTypeAdapter(Properties.class, propertiesAdapter.nullSafe());
builder.registerTypeAdapter(Date.class, adapter.nullSafe());
builder.registerTypeAdapter(new TypeToken<List<Byte>>() {
}.getType(), byteListAdapter.nullSafe());
builder.registerTypeAdapter(byte[].class, byteArrayAdapter.nullSafe());
builder.registerTypeAdapter(JsonBall.class, jsonAdapter.nullSafe());
builder.registerTypeAdapterFactory(optional);
builder.registerTypeAdapterFactory(iterable);
builder.registerTypeAdapterFactory(collection);
builder.registerTypeAdapterFactory(list);
builder.registerTypeAdapter(new TypeToken<List<Byte>>() {
}.getType(), byteListAdapter.nullSafe());
builder.registerTypeAdapterFactory(immutableList);
builder.registerTypeAdapterFactory(set);
builder.registerTypeAdapterFactory(immutableSet);

View File

@ -18,8 +18,11 @@
*/
package org.jclouds.json;
import static com.google.common.io.BaseEncoding.base16;
import static com.google.common.primitives.Bytes.asList;
import static org.testng.Assert.assertEquals;
import java.util.List;
import java.util.Map;
import java.util.Properties;
@ -113,6 +116,17 @@ public class JsonTest {
private Test enumValue;
}
private static class ByteList {
List<Byte> checksum;
}
public void testByteList() {
ByteList bl = new ByteList();
bl.checksum = asList(base16().lowerCase().decode("1dda05ed139664f1f89b9dec482b77c0"));
assertEquals(json.toJson(bl), "{\"checksum\":\"1dda05ed139664f1f89b9dec482b77c0\"}");
assertEquals(json.fromJson(json.toJson(bl), ByteList.class).checksum, bl.checksum);
}
public void testPropertiesSerializesDefaults() {
Properties props = new Properties();
props.put("string", "string");