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"]

See you at Web, MicroProfile and Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting. Is Munich's airport too far? Learn from home: airhacks.io.


Web Apps, SPA, PWA with vanilla Java Script (ES 6+), CSS 3 and WebStandards only. As simple as possible, but not simpler. See you at: (Progressive) Web apps, Single Page Apps and WebStandards airhacks workshops at MUC airport, Winter Edition

airhacks.fm the podcast:

Stay in touch: airhacks.news.

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
Online Workshops
realworldpatterns.com
...the last 150 posts
...the last 10 comments
License