mirror of https://github.com/apache/jclouds.git
Adding gson adaptor for HostResourceUsage
This commit is contained in:
parent
1d09fc3400
commit
43d258837d
|
@ -25,8 +25,15 @@ import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.json.config.GsonModule;
|
import org.jclouds.json.config.GsonModule;
|
||||||
import org.jclouds.json.config.GsonModule.DateAdapter;
|
import org.jclouds.json.config.GsonModule.DateAdapter;
|
||||||
|
import org.jclouds.openstack.nova.v1_1.domain.HostResourceUsage;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import com.google.gson.JsonDeserializationContext;
|
||||||
|
import com.google.gson.JsonDeserializer;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonParseException;
|
||||||
|
import com.google.gson.JsonSerializationContext;
|
||||||
|
import com.google.gson.JsonSerializer;
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
|
|
||||||
|
@ -38,7 +45,7 @@ public class NovaParserModule extends AbstractModule {
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
public Map<Type, Object> provideCustomAdapterBindings() {
|
public Map<Type, Object> provideCustomAdapterBindings() {
|
||||||
return ImmutableMap.<Type, Object> of();
|
return ImmutableMap.<Type, Object> of(HostResourceUsage.class, new HostResourceUsageAdapter());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -46,4 +53,30 @@ public class NovaParserModule extends AbstractModule {
|
||||||
bind(DateAdapter.class).to(GsonModule.Iso8601DateAdapter.class);
|
bind(DateAdapter.class).to(GsonModule.Iso8601DateAdapter.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
public static class HostResourceUsageAdapter implements JsonSerializer<HostResourceUsage>, JsonDeserializer<HostResourceUsage> {
|
||||||
|
public HostResourceUsage apply(HostResourceUsageWrapper in) {
|
||||||
|
return in.resource.toBuilder().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HostResourceUsage deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException {
|
||||||
|
return apply((HostResourceUsageWrapper) context.deserialize(jsonElement, HostResourceUsageWrapper.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JsonElement serialize(HostResourceUsage hostResourceUsage, Type type, JsonSerializationContext context) {
|
||||||
|
return context.serialize(hostResourceUsage);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class HostResourceUsageWrapper {
|
||||||
|
protected HostResourceUsageInternal resource;
|
||||||
|
}
|
||||||
|
private static class HostResourceUsageInternal extends HostResourceUsage {
|
||||||
|
protected HostResourceUsageInternal(Builder<?> builder) {
|
||||||
|
super(builder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue