package kr.co.swh.lecture.opensource.jackson;

import java.io.InputStream;

import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * <pre>
 * kr.co.swh.lecture.opensource.jackson
 * JacksonMain.java
 *
 * 설명 :Jackson 예제
 * </pre>
 * 
 * @since : 2018. 1. 29.
 * @author : tobby48
 * @version : v1.0
 */
public class JacksonMain {
	
	private ObjectMapper mapper = new ObjectMapper();
	private InputStream is;
	
	@SuppressWarnings("static-access")
	public JacksonMain(){
		is = Thread.currentThread().getContextClassLoader().getSystemResourceAsStream("json.json");
	}
	
	public void print() throws Exception{
		StudentList value = mapper.readValue(is, StudentList.class);
		System.out.println(value);
	}
	
	public void write() throws Exception{
		Student s1 = new Student();
		s1.setName("돌쌤");
		s1.setAge(18);
		System.out.println(mapper.writeValueAsString(s1));
	}
	
	public static void main(String[] args) throws Exception  {
		// TODO Auto-generated method stub
		JacksonMain jackson = new JacksonMain();
		jackson.print();
		jackson.write();
	}

}
