List to JsonArray Conversion with JSON-P and Java EE 8 📎
List<String>
can be converted into JsonArray
with:
import javax.json.Json;
import javax.json.JsonArray;
import javax.json.stream.JsonCollectors;
import org.junit.jupiter.api.Test;
public class StringListToJsonArrayTest {
@Test
public void conversion() {
JsonArray jsonStringArray = Arrays.asList("duke", "duchess").
stream().
map(Json::createValue).
collect(JsonCollectors.toJsonArray());
System.out.println(jsonStringArray);
}
}
...and the result is: ["duke","duchess"]