A few bug fixes.

This commit is contained in:
James M Snell 2014-04-28 18:11:45 -07:00
parent cb0a252911
commit c4a4f1c3b0
3 changed files with 38 additions and 21 deletions

View File

@ -212,19 +212,11 @@ public final class GsonWrapper {
Schema.make().get(); Schema.make().get();
ASObjectAdapter base = ASObjectAdapter base =
new ASObjectAdapter(schema); new ASObjectAdapter(schema);
GsonBuilder b = initGsonBuilder(builder,schema,base); GsonBuilder b = initGsonBuilder(
for (AdapterEntry<?> entry : builder.adapters.build()) { builder,
if (entry.hier) schema,
b.registerTypeHierarchyAdapter( base,
entry.type, builder.adapters.build());
entry.adapter!=null ?
entry.adapter : base);
else
b.registerTypeAdapter(
entry.type,
entry.adapter!=null ?
entry.adapter:base);
}
if (builder.pretty) if (builder.pretty)
b.setPrettyPrinting(); b.setPrettyPrinting();
this.gson = b.create(); this.gson = b.create();
@ -239,12 +231,29 @@ public final class GsonWrapper {
private static GsonBuilder initGsonBuilder( private static GsonBuilder initGsonBuilder(
Builder builder, Builder builder,
Schema schema, Schema schema,
ASObjectAdapter base) { ASObjectAdapter base,
return new GsonBuilder() Iterable<AdapterEntry<?>> adapters) {
GsonBuilder gson = new GsonBuilder()
.registerTypeHierarchyAdapter(TypeValue.class, new TypeValueAdapter(schema)) .registerTypeHierarchyAdapter(TypeValue.class, new TypeValueAdapter(schema))
.registerTypeHierarchyAdapter(LinkValue.class, new LinkValueAdapter(schema)) .registerTypeHierarchyAdapter(LinkValue.class, new LinkValueAdapter(schema))
.registerTypeHierarchyAdapter(Iterable.class, ITERABLE);
for (AdapterEntry<?> entry : adapters) {
if (entry.hier)
gson.registerTypeHierarchyAdapter(
entry.type,
entry.adapter!=null ?
entry.adapter : base);
else
gson.registerTypeAdapter(
entry.type,
entry.adapter!=null ?
entry.adapter:base);
}
return gson
.registerTypeHierarchyAdapter(NLV.class, NLV) .registerTypeHierarchyAdapter(NLV.class, NLV)
.registerTypeHierarchyAdapter(Iterable.class, ITERABLE)
.registerTypeHierarchyAdapter(ActionsValue.class, ACTIONS) .registerTypeHierarchyAdapter(ActionsValue.class, ACTIONS)
.registerTypeHierarchyAdapter(Optional.class, OPTIONAL) .registerTypeHierarchyAdapter(Optional.class, OPTIONAL)
.registerTypeHierarchyAdapter(Range.class, RANGE) .registerTypeHierarchyAdapter(Range.class, RANGE)

View File

@ -200,10 +200,16 @@ public final class Schema {
return this; return this;
} }
public Model model(String objectType) {
return objectTypeMap.get(objectType);
}
public Model model() {
return objectClassMap.get(ASObject.Builder.class);
}
/** /**
* Method get. * Method get.
* @return Schema * @see com.google.common.base.Supplier#get() */ * @return Schema * @see com.google.common.base.Supplier#get() */
public Schema get() { public Schema get() {
return new Schema(this); return new Schema(this);

View File

@ -18,6 +18,7 @@ import org.apache.http.config.RegistryBuilder;
import org.apache.http.config.SocketConfig; import org.apache.http.config.SocketConfig;
import org.apache.http.conn.HttpClientConnectionManager; import org.apache.http.conn.HttpClientConnectionManager;
import org.apache.http.conn.socket.ConnectionSocketFactory; import org.apache.http.conn.socket.ConnectionSocketFactory;
import org.apache.http.conn.socket.PlainConnectionSocketFactory;
import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.client.HttpClients;
@ -43,7 +44,8 @@ public final class HttpFetch
implements Supplier<HttpFetch> { implements Supplier<HttpFetch> {
private final RegistryBuilder<ConnectionSocketFactory> csfr = private final RegistryBuilder<ConnectionSocketFactory> csfr =
RegistryBuilder.<ConnectionSocketFactory>create(); RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", PlainConnectionSocketFactory.INSTANCE);
private ConnectionConfig defaultConnectionConfig; private ConnectionConfig defaultConnectionConfig;
private SocketConfig defaultSocketConfig; private SocketConfig defaultSocketConfig;
private final ImmutableMap.Builder<HttpHost,ConnectionConfig> connectionConfigs = private final ImmutableMap.Builder<HttpHost,ConnectionConfig> connectionConfigs =