I have a Java map:
Map<String, Object> data = new HashMap<String, Object>();
And I am doing following put
operation on it by:
data.put("case_ids", Arrays.asList(22222));
where case_ids
is the attribute for 3rd party API and it accept int values. Here when I input multiple int
values in Arrays.asList()
, the Api request works fine. For example, Arrays.asList(22222, 1111)
works with no issues. However, there is a case where I will have different 100 int values and it will not be a good way to have all the values directly in the code/method. So, I am thinking of creating a constant.java class and have
public static final int[] CASES = {
11111, 22222, 33333, 44444, 55555,....
};
in the constants java class. However when I make a call to
data.put("case_ids", Arrays.asList(Constants.CASES));
, I get the API exception of Invalid JSON request.
I do not use Java 8 and so, stream() function would not work for me. I tried this Arrays.stream(VALUES).boxed().collect(Collectors.toList())
as per Java List Object instead of an Array.