// Collection of code snippets by Arne Vajhøj 
// (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
package jsonproc;

import javax.json.bind.Jsonb;
import javax.json.bind.JsonbBuilder;

public class BindJSONB {
    private static final String json = "[ { \"no\" : 1, \"name\" : \"Alan A\", \"role\" : \"Manager\" }, " +
                                         "{ \"no\" : 2, \"name\" : \"Brian B\", \"role\" : \"Engineer\" }, " +
                                         "{ \"no\" : 3, \"name\" : \"Chris C\", \"role\" : \"Sales rep\" } ]";
    public static void main(String[] args) {
        Jsonb b = JsonbBuilder.create();
        // read
        Employee[] employees = b.fromJson(json, Employee[].class);
        for(Employee employee : employees) {
            System.out.println(employee);
        }
        // write
        System.out.println(b.toJson(employees));
    }
}
