@Test public void shouldConcatenateParams() throws IOException { FormEncoded encoded = new FormEncoded(); StringWriter writer = new StringWriter(); Map<String, String > params = new HashMap<String, String>(); params.put("name", "Guilherme"); params.put("age", "29"); encoded.marshal(params, writer, new DefaultRestClient()); assertThat(writer.toString(), Matchers.anyOf(is(CoreMatchers.equalTo("name=Guilherme&age=29")), is(CoreMatchers.equalTo("age=29&name=Guilherme")))); }
@SuppressWarnings("unchecked") public <T> void marshal(T payload, Writer writer, RestClient client) throws IOException { if(payload.getClass().equals(String.class)) { writer.append(String.class.cast(payload)); return; } Map<String, String> params = (Map<String, String>) payload; int at = 0; for (Entry<String, String> param : params.entrySet()) { writer.append(URLEncoder.encode(param.getKey())); writer.append("="); writer.append(URLEncoder.encode(param.getValue())); if (++at != params.size()) { writer.append("&"); } } }
FormEncoded implements MediaType { @SuppressWarnings("unchecked") public <T> void marshal(T payload, Writer writer, RestClient client) throws IOException { if(payload.getClass().equals(String.class)) { writer.append(String.class.cast(payload)); return; } Map<String, String> params = (Map<String, String>) payload; int at = 0; for (Entry<String, String> param : params.entrySet()) { writer.append(URLEncoder.encode(param.getKey())); writer.append("="); writer.append(URLEncoder.encode(param.getValue())); if (++at != params.size()) { writer.append("&"); } } } }
FormEncoded implements MediaType { @SuppressWarnings("unchecked") public <T> void marshal(T payload, Writer writer, RestClient client) throws IOException { if(payload.getClass().equals(String.class)) { writer.append(String.class.cast(payload)); return; } Map<String, String> params = (Map<String, String>) payload; int at = 0; for (Entry<String, String> param : params.entrySet()) { writer.append(URLEncoder.encode(param.getKey())); writer.append("="); writer.append(URLEncoder.encode(param.getValue())); if (++at != params.size()) { writer.append("&"); } } }  }
FormEncoded implements MediaType { @SuppressWarnings("unchecked") public <T> void marshal(T payload, Writer writer, RestClient client) throws IOException { if(payload.getClass().equals(String.class)) { writer.append(String.class.cast(payload)); return; } Map<String, String> params = (Map<String, String>) payload; int at = 0; for (Entry<String, String> param : params.entrySet()) { writer.append(URLEncoder.encode(param.getKey())); writer.append("="); writer.append(URLEncoder.encode(param.getValue())); if (++at != params.size()) { writer.append("&"); } } }  boolean answersTo(String type); @SuppressWarnings("unchecked") void marshal(T payload, Writer writer, RestClient client); T unmarshal(String content, RestClient client); }
FormEncoded implements MediaType { @SuppressWarnings("unchecked") public <T> void marshal(T payload, Writer writer, RestClient client) throws IOException { if(payload.getClass().equals(String.class)) { writer.append(String.class.cast(payload)); return; } Map<String, String> params = (Map<String, String>) payload; int at = 0; for (Entry<String, String> param : params.entrySet()) { writer.append(URLEncoder.encode(param.getKey())); writer.append("="); writer.append(URLEncoder.encode(param.getValue())); if (++at != params.size()) { writer.append("&"); } } }  boolean answersTo(String type); @SuppressWarnings("unchecked") void marshal(T payload, Writer writer, RestClient client); T unmarshal(String content, RestClient client);  }