how to convert List<object> into org.json.JSONArray? how to convert List<object> into org.json.JSONArray? json json

how to convert List<object> into org.json.JSONArray?


Since arrays are objects in java and being treated as references instead of values so to get the string representation of your array you can use Arrays#toString

obj.put("business_images", Arrays.toString(business_images) );

To get JSONArray use

obj.put("business_images", new JSONArray(Arrays.toString(business_images)));

and since JSONObject support int,long,double,boolean so you don't need to promote primitive to String but if your REST API expecting all as string then use String.valueOf for performance efficiency

obj.put("chat_id", String.valueOf(chat_id));


 ObjectMapper mapper = new ObjectMapper();   System.out.println(mapper.writeValueAsString(list));