You can use the following code to transform a byte[] array in Java Gson into an ArrayList:
byte[] byteArray = /* your byte[] array */;
String json = new String(byteArray, StandardCharsets.UTF_8);
Type listType = new TypeToken<ArrayList<String>>() {}.getType();
ArrayList<String> arrayList = new Gson().fromJson(json, listType);
In this code snippet, we first convert the byte array into a JSON string using UTF-8 encoding. Then we define a TypeToken
to specify the type of the ArrayList that we want to deserialize. Finally, we use the fromJson
method of the Gson library to convert the JSON string into an ArrayList object.
Asked: 2021-06-23 11:00:00 +0000
Seen: 13 times
Last updated: Oct 24 '21