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

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class BindJackson {
    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) throws JsonMappingException, JsonProcessingException {
    	ObjectMapper om = new ObjectMapper();
        // read
        Employee[] employees = om.readValue(json, Employee[].class);
        for(Employee employee : employees) {
            System.out.println(employee);
        }
        // write
        System.out.println(om.writeValueAsString(employees));
    }
}
