RestParameterBindingsSerializer { public String serialize(RestParameterBindings parameterBindings) { StringBuilder result = new StringBuilder("{"); for (Entry<HttpMethod, Set<HttpParameter>> entry : parameterBindings.entrySet()) { serializeValues(result, entry.getKey(), entry.getValue()); } if (!parameterBindings.isEmpty()) { result.deleteCharAt(result.length() - 1); } result.append("}"); return result.toString(); } RestParameterBindingsSerializer(); String serialize(RestParameterBindings parameterBindings); RestParameterBindings deserialize(String encodedParameters);  }
@Test public void serializeEmpty() { RestParameterBindings map = new RestParameterBindings(); String serialized = serializer.serialize(map); assertEquals("{}", serialized); }
@Test public void serializeSimple() { RestParameterBindings map = new RestParameterBindings(); map.put(HttpMethod.GET, new QueryParameter("a", 1, null, URL_UTILS)); String serialized = serializer.serialize(map); assertEquals("{\"GET\":[{\"type\": \"QUERY\", \"key\": \"a\", \"value\": \"1\"}]}", serialized); }
@Test public void serializeComplex() { RestParameterBindings map = new RestParameterBindings(); map.put(HttpMethod.GET, new QueryParameter("a", 1, null, URL_UTILS)); map.put(HttpMethod.GET, new FormParameter("b", false, null, URL_UTILS)); map.put(HttpMethod.POST, new HeaderParameter("c", "some string", null)); map.put(HttpMethod.POST, new PathParameter("d", 29L, null, null, URL_UTILS)); String serialized = serializer.serialize(map); assertEquals("{\"GET\":[" + "{\"type\": \"QUERY\", \"key\": \"a\", \"value\": \"1\"}," + "{\"type\": \"FORM\", \"key\": \"b\", \"value\": \"false\"}]," + "\"POST\":[" + "{\"type\": \"HEADER\", \"key\": \"c\", \"value\": \"some string\"}," + "{\"type\": \"PATH\", \"key\": \"d\", \"value\": \"29\"}]}", serialized); }