@Test public void testUtf8() throws Exception { String query = "fields=[first, second, third]" + "&offset=0" + "&limit=55" + "&filters={age:12, name:Арт%26уሴр}" + "&sort=[[name,asc]]" + "&extra=[]"; HttpRequest req = HttpRequest.get("http: Gson gson = new Gson(); ReadSettings<?> settings = ReadSettings.from(gson, req); assertEquals("Арт&уሴр", settings.getFilters().get("name")); }
public static <K> ReadSettings<K> from(Gson gson, HttpRequest request) throws ParseException { String fieldsParameter = request.getQueryParameter("fields"); List<String> fields; if (fieldsParameter != null && !fieldsParameter.isEmpty()) { fields = fromJson(gson, fieldsParameter, LIST_STRING_TYPE_TOKEN); } else { fields = Collections.emptyList(); } String offsetParameter = request.getQueryParameter("offset"); int offset = DEFAULT_OFFSET; if (offsetParameter != null && !offsetParameter.isEmpty()) { offset = trimAndDecodePositiveInt(encodeAscii(offsetParameter), 0, offsetParameter.length()); } String limitParameter = request.getQueryParameter("limit"); int limit = DEFAULT_LIMIT; if (limitParameter != null && !limitParameter.isEmpty()) { limit = trimAndDecodePositiveInt(encodeAscii(limitParameter), 0, limitParameter.length()); } String filtersParameter = request.getQueryParameter("filters"); Map<String, String> filters; if (filtersParameter != null && !filtersParameter.isEmpty()) { filters = fromJson(gson, filtersParameter, MAP_STRING_STRING_TYPE_TOKEN); filters = Collections.unmodifiableMap(filters); } else { filters = Collections.emptyMap(); } String sortParameter = request.getQueryParameter("sort"); Map<String, SortOrder> sort; if (sortParameter != null && !sortParameter.isEmpty()) { sort = new LinkedHashMap<>(); JsonArray array = fromJson(gson, sortParameter, JsonArray.class); String key; SortOrder value; for (JsonElement element : array) { JsonArray arr = element.getAsJsonArray(); key = arr.get(0).getAsString(); value = SortOrder.of(arr.get(1).getAsString()); sort.put(key, value); } sort = Collections.unmodifiableMap(sort); } else { sort = Collections.emptyMap(); } String extraParameter = request.getQueryParameter("extra"); Set<K> extra; if (extraParameter != null && !extraParameter.isEmpty()) { extra = fromJson(gson, extraParameter, new TypeToken<LinkedHashSet<K>>() {}.getType()); } else { extra = Collections.emptySet(); } return new ReadSettings<>(fields, offset, limit, filters, sort, extra); }
ReadSettings { public static <K> ReadSettings<K> from(Gson gson, HttpRequest request) throws ParseException { String fieldsParameter = request.getQueryParameter("fields"); List<String> fields; if (fieldsParameter != null && !fieldsParameter.isEmpty()) { fields = fromJson(gson, fieldsParameter, LIST_STRING_TYPE_TOKEN); } else { fields = Collections.emptyList(); } String offsetParameter = request.getQueryParameter("offset"); int offset = DEFAULT_OFFSET; if (offsetParameter != null && !offsetParameter.isEmpty()) { offset = trimAndDecodePositiveInt(encodeAscii(offsetParameter), 0, offsetParameter.length()); } String limitParameter = request.getQueryParameter("limit"); int limit = DEFAULT_LIMIT; if (limitParameter != null && !limitParameter.isEmpty()) { limit = trimAndDecodePositiveInt(encodeAscii(limitParameter), 0, limitParameter.length()); } String filtersParameter = request.getQueryParameter("filters"); Map<String, String> filters; if (filtersParameter != null && !filtersParameter.isEmpty()) { filters = fromJson(gson, filtersParameter, MAP_STRING_STRING_TYPE_TOKEN); filters = Collections.unmodifiableMap(filters); } else { filters = Collections.emptyMap(); } String sortParameter = request.getQueryParameter("sort"); Map<String, SortOrder> sort; if (sortParameter != null && !sortParameter.isEmpty()) { sort = new LinkedHashMap<>(); JsonArray array = fromJson(gson, sortParameter, JsonArray.class); String key; SortOrder value; for (JsonElement element : array) { JsonArray arr = element.getAsJsonArray(); key = arr.get(0).getAsString(); value = SortOrder.of(arr.get(1).getAsString()); sort.put(key, value); } sort = Collections.unmodifiableMap(sort); } else { sort = Collections.emptyMap(); } String extraParameter = request.getQueryParameter("extra"); Set<K> extra; if (extraParameter != null && !extraParameter.isEmpty()) { extra = fromJson(gson, extraParameter, new TypeToken<LinkedHashSet<K>>() {}.getType()); } else { extra = Collections.emptySet(); } return new ReadSettings<>(fields, offset, limit, filters, sort, extra); } }
ReadSettings { public static <K> ReadSettings<K> from(Gson gson, HttpRequest request) throws ParseException { String fieldsParameter = request.getQueryParameter("fields"); List<String> fields; if (fieldsParameter != null && !fieldsParameter.isEmpty()) { fields = fromJson(gson, fieldsParameter, LIST_STRING_TYPE_TOKEN); } else { fields = Collections.emptyList(); } String offsetParameter = request.getQueryParameter("offset"); int offset = DEFAULT_OFFSET; if (offsetParameter != null && !offsetParameter.isEmpty()) { offset = trimAndDecodePositiveInt(encodeAscii(offsetParameter), 0, offsetParameter.length()); } String limitParameter = request.getQueryParameter("limit"); int limit = DEFAULT_LIMIT; if (limitParameter != null && !limitParameter.isEmpty()) { limit = trimAndDecodePositiveInt(encodeAscii(limitParameter), 0, limitParameter.length()); } String filtersParameter = request.getQueryParameter("filters"); Map<String, String> filters; if (filtersParameter != null && !filtersParameter.isEmpty()) { filters = fromJson(gson, filtersParameter, MAP_STRING_STRING_TYPE_TOKEN); filters = Collections.unmodifiableMap(filters); } else { filters = Collections.emptyMap(); } String sortParameter = request.getQueryParameter("sort"); Map<String, SortOrder> sort; if (sortParameter != null && !sortParameter.isEmpty()) { sort = new LinkedHashMap<>(); JsonArray array = fromJson(gson, sortParameter, JsonArray.class); String key; SortOrder value; for (JsonElement element : array) { JsonArray arr = element.getAsJsonArray(); key = arr.get(0).getAsString(); value = SortOrder.of(arr.get(1).getAsString()); sort.put(key, value); } sort = Collections.unmodifiableMap(sort); } else { sort = Collections.emptyMap(); } String extraParameter = request.getQueryParameter("extra"); Set<K> extra; if (extraParameter != null && !extraParameter.isEmpty()) { extra = fromJson(gson, extraParameter, new TypeToken<LinkedHashSet<K>>() {}.getType()); } else { extra = Collections.emptySet(); } return new ReadSettings<>(fields, offset, limit, filters, sort, extra); } private  ReadSettings(List<String> fields,
			int offset,
			int limit,
			Map<String, String> filters,
			Map<String, SortOrder> sort,
			Set<K> extra); }
ReadSettings { public static <K> ReadSettings<K> from(Gson gson, HttpRequest request) throws ParseException { String fieldsParameter = request.getQueryParameter("fields"); List<String> fields; if (fieldsParameter != null && !fieldsParameter.isEmpty()) { fields = fromJson(gson, fieldsParameter, LIST_STRING_TYPE_TOKEN); } else { fields = Collections.emptyList(); } String offsetParameter = request.getQueryParameter("offset"); int offset = DEFAULT_OFFSET; if (offsetParameter != null && !offsetParameter.isEmpty()) { offset = trimAndDecodePositiveInt(encodeAscii(offsetParameter), 0, offsetParameter.length()); } String limitParameter = request.getQueryParameter("limit"); int limit = DEFAULT_LIMIT; if (limitParameter != null && !limitParameter.isEmpty()) { limit = trimAndDecodePositiveInt(encodeAscii(limitParameter), 0, limitParameter.length()); } String filtersParameter = request.getQueryParameter("filters"); Map<String, String> filters; if (filtersParameter != null && !filtersParameter.isEmpty()) { filters = fromJson(gson, filtersParameter, MAP_STRING_STRING_TYPE_TOKEN); filters = Collections.unmodifiableMap(filters); } else { filters = Collections.emptyMap(); } String sortParameter = request.getQueryParameter("sort"); Map<String, SortOrder> sort; if (sortParameter != null && !sortParameter.isEmpty()) { sort = new LinkedHashMap<>(); JsonArray array = fromJson(gson, sortParameter, JsonArray.class); String key; SortOrder value; for (JsonElement element : array) { JsonArray arr = element.getAsJsonArray(); key = arr.get(0).getAsString(); value = SortOrder.of(arr.get(1).getAsString()); sort.put(key, value); } sort = Collections.unmodifiableMap(sort); } else { sort = Collections.emptyMap(); } String extraParameter = request.getQueryParameter("extra"); Set<K> extra; if (extraParameter != null && !extraParameter.isEmpty()) { extra = fromJson(gson, extraParameter, new TypeToken<LinkedHashSet<K>>() {}.getType()); } else { extra = Collections.emptySet(); } return new ReadSettings<>(fields, offset, limit, filters, sort, extra); } private  ReadSettings(List<String> fields,
			int offset,
			int limit,
			Map<String, String> filters,
			Map<String, SortOrder> sort,
			Set<K> extra); static ReadSettings<K> from(Gson gson, HttpRequest request); static ReadSettings<K> of(List<String> fields,
			int offset,
			int limit,
			Map<String, String> filters,
			Map<String, SortOrder> sort,
			Set<K> extra); List<String> getFields(); int getOffset(); int getLimit(); Map<String, String> getFilters(); Map<String, SortOrder> getSort(); Set<K> getExtra(); @Override String toString(); }
ReadSettings { public static <K> ReadSettings<K> from(Gson gson, HttpRequest request) throws ParseException { String fieldsParameter = request.getQueryParameter("fields"); List<String> fields; if (fieldsParameter != null && !fieldsParameter.isEmpty()) { fields = fromJson(gson, fieldsParameter, LIST_STRING_TYPE_TOKEN); } else { fields = Collections.emptyList(); } String offsetParameter = request.getQueryParameter("offset"); int offset = DEFAULT_OFFSET; if (offsetParameter != null && !offsetParameter.isEmpty()) { offset = trimAndDecodePositiveInt(encodeAscii(offsetParameter), 0, offsetParameter.length()); } String limitParameter = request.getQueryParameter("limit"); int limit = DEFAULT_LIMIT; if (limitParameter != null && !limitParameter.isEmpty()) { limit = trimAndDecodePositiveInt(encodeAscii(limitParameter), 0, limitParameter.length()); } String filtersParameter = request.getQueryParameter("filters"); Map<String, String> filters; if (filtersParameter != null && !filtersParameter.isEmpty()) { filters = fromJson(gson, filtersParameter, MAP_STRING_STRING_TYPE_TOKEN); filters = Collections.unmodifiableMap(filters); } else { filters = Collections.emptyMap(); } String sortParameter = request.getQueryParameter("sort"); Map<String, SortOrder> sort; if (sortParameter != null && !sortParameter.isEmpty()) { sort = new LinkedHashMap<>(); JsonArray array = fromJson(gson, sortParameter, JsonArray.class); String key; SortOrder value; for (JsonElement element : array) { JsonArray arr = element.getAsJsonArray(); key = arr.get(0).getAsString(); value = SortOrder.of(arr.get(1).getAsString()); sort.put(key, value); } sort = Collections.unmodifiableMap(sort); } else { sort = Collections.emptyMap(); } String extraParameter = request.getQueryParameter("extra"); Set<K> extra; if (extraParameter != null && !extraParameter.isEmpty()) { extra = fromJson(gson, extraParameter, new TypeToken<LinkedHashSet<K>>() {}.getType()); } else { extra = Collections.emptySet(); } return new ReadSettings<>(fields, offset, limit, filters, sort, extra); } private  ReadSettings(List<String> fields,
			int offset,
			int limit,
			Map<String, String> filters,
			Map<String, SortOrder> sort,
			Set<K> extra); static ReadSettings<K> from(Gson gson, HttpRequest request); static ReadSettings<K> of(List<String> fields,
			int offset,
			int limit,
			Map<String, String> filters,
			Map<String, SortOrder> sort,
			Set<K> extra); List<String> getFields(); int getOffset(); int getLimit(); Map<String, String> getFilters(); Map<String, SortOrder> getSort(); Set<K> getExtra(); @Override String toString();  }