@Test public void testMap() throws SecurityException, NoSuchMethodException { DiskCreationOptions diskCreationOptions = new DiskCreationOptions.Builder() .sourceSnapshot(URI.create(FAKE_SOURCE_SNAPSHOT)).sizeGb(15).description(null).build(); HttpRequest request = HttpRequest.builder().method("GET").endpoint("http: Map<String, Object> postParams = ImmutableMap.of("name", "testName", "options", diskCreationOptions); request = binder.bindToRequest(request, postParams); assertEquals(request.getPayload().getRawContent(), "{\"name\":\"testName\",\"sizeGb\":15,\"sourceSnapshot\":\"" + FAKE_SOURCE_SNAPSHOT + "\"}"); assertEquals(request.getPayload().getContentMetadata().getContentType(), "application/json"); }
@Override public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) { DiskCreationOptions options = (DiskCreationOptions) postParams.get("options"); Writer out = new StringWriter(); JsonWriter json = new JsonWriter(out); json.setSerializeNulls(false); try { json.beginObject(); json.name("name").value(postParams.get("name").toString()); json.name("sizeGb").value(options.sizeGb()); json.name("type").value(options.type() != null ? options.type().toString() : null); json.name("sourceSnapshot") .value(options.sourceSnapshot() != null ? options.sourceSnapshot().toString() : null); json.name("description").value(options.description()); json.endObject(); json.close(); } catch (IOException e) { throw new AssertionError(e); } request.setPayload(out.toString()); request.getPayload().getContentMetadata().setContentType("application/json"); return request; }
DiskCreationBinder implements MapBinder { @Override public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) { DiskCreationOptions options = (DiskCreationOptions) postParams.get("options"); Writer out = new StringWriter(); JsonWriter json = new JsonWriter(out); json.setSerializeNulls(false); try { json.beginObject(); json.name("name").value(postParams.get("name").toString()); json.name("sizeGb").value(options.sizeGb()); json.name("type").value(options.type() != null ? options.type().toString() : null); json.name("sourceSnapshot") .value(options.sourceSnapshot() != null ? options.sourceSnapshot().toString() : null); json.name("description").value(options.description()); json.endObject(); json.close(); } catch (IOException e) { throw new AssertionError(e); } request.setPayload(out.toString()); request.getPayload().getContentMetadata().setContentType("application/json"); return request; } }
DiskCreationBinder implements MapBinder { @Override public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) { DiskCreationOptions options = (DiskCreationOptions) postParams.get("options"); Writer out = new StringWriter(); JsonWriter json = new JsonWriter(out); json.setSerializeNulls(false); try { json.beginObject(); json.name("name").value(postParams.get("name").toString()); json.name("sizeGb").value(options.sizeGb()); json.name("type").value(options.type() != null ? options.type().toString() : null); json.name("sourceSnapshot") .value(options.sourceSnapshot() != null ? options.sourceSnapshot().toString() : null); json.name("description").value(options.description()); json.endObject(); json.close(); } catch (IOException e) { throw new AssertionError(e); } request.setPayload(out.toString()); request.getPayload().getContentMetadata().setContentType("application/json"); return request; }  }
DiskCreationBinder implements MapBinder { @Override public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) { DiskCreationOptions options = (DiskCreationOptions) postParams.get("options"); Writer out = new StringWriter(); JsonWriter json = new JsonWriter(out); json.setSerializeNulls(false); try { json.beginObject(); json.name("name").value(postParams.get("name").toString()); json.name("sizeGb").value(options.sizeGb()); json.name("type").value(options.type() != null ? options.type().toString() : null); json.name("sourceSnapshot") .value(options.sourceSnapshot() != null ? options.sourceSnapshot().toString() : null); json.name("description").value(options.description()); json.endObject(); json.close(); } catch (IOException e) { throw new AssertionError(e); } request.setPayload(out.toString()); request.getPayload().getContentMetadata().setContentType("application/json"); return request; }  @Override R bindToRequest(R request, Map<String, Object> postParams); @Override R bindToRequest(R request, Object input); }
DiskCreationBinder implements MapBinder { @Override public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) { DiskCreationOptions options = (DiskCreationOptions) postParams.get("options"); Writer out = new StringWriter(); JsonWriter json = new JsonWriter(out); json.setSerializeNulls(false); try { json.beginObject(); json.name("name").value(postParams.get("name").toString()); json.name("sizeGb").value(options.sizeGb()); json.name("type").value(options.type() != null ? options.type().toString() : null); json.name("sourceSnapshot") .value(options.sourceSnapshot() != null ? options.sourceSnapshot().toString() : null); json.name("description").value(options.description()); json.endObject(); json.close(); } catch (IOException e) { throw new AssertionError(e); } request.setPayload(out.toString()); request.getPayload().getContentMetadata().setContentType("application/json"); return request; }  @Override R bindToRequest(R request, Map<String, Object> postParams); @Override R bindToRequest(R request, Object input);  }