6월 16일 딱~ 하루하는 행사가 있군요.... :: 2009/06/16 13:45
우연히 RSS 리더를 읽다가 6월 16일 딱 하루만 하는 행사가 있어서 재미삼아 참여해 보았습니다.
다음세대재단에서 주관하는 매일매일 다르게 변화하는 웹페이지를 하루동안 그 역사를 담는 타임캡슐처럼 담는 것입니다.
자신이 올리고 싶은 웹페이지를 캡쳐해서 전송하여 미래에 2009년 6월 16일엔 어떤 웹페이지가 존재했었나 어떤 내용이었나를 확인할 수 있는 뜻깊은 행사 같아서 저도 한번 제 블로그를 올려보았습니다.
전시관에서는 작년 이때, 제작년 이때를 둘러볼 수도 있습니다.
블로그를 가지고 계신분이나, 남기고 싶은 웹페이지가 있다면 한번 올려보시는것도..
적긴 하지만 경품도 준다고 합니다.
'잡동재미꺼리' 카테고리의 다른 글
| 6월 16일 딱~ 하루하는 행사가 있군요.... (3) | 2009/06/16 |
|---|---|
| 내가 다녀온 나라를 지도로 표시해보니 (4) | 2009/02/23 |
| iPhone이 이젠 큐브도 맞춰주는구나.. (4) | 2009/02/09 |
| HP 컬러 레이저젯 CP1215 체험단 모집에 응모를... (8) | 2008/07/08 |
| "버리" 님의 가치는 419억8773만7594원 입니다. (4) | 2008/05/02 |
| 당신에게 뻔한 것, 따라하기, 지루한 것은 죄악입니다. (2) | 2008/03/08 |
| 블로그 중독 지수 (19) | 2007/10/24 |
| 귀를 사수하라! (14) | 2007/09/11 |
| 이름풀이로 보는 나의 뇌... (10) | 2007/08/28 |
Jersey의 JSON Support :: 2009/06/08 13:57
Jersey에서 JSON을 지원하는 방법은 두가지가 있다.
* JAXB Based JSON support
* Low-Level JSON support
일단, JAXB 기반의 JSON 지원하는 방법을 알아보면,
JSON하고 XML data format을 쉽게 produce/consume하면 시간절약을 할 수 있다.
왜냐면 Java model, JAXB를 이용한 annotated된 POJO를 쓰기때문에 쉽게 핸들링할 수 있다.
자바 모델에 @XmlRootElement 어노테이션을 붙여주고 간단한 몇가지 작업을 해주면~ 큰 노력하지 않고
JSON을 지원할 수 있다.
단점은 매우 특별한 JSON format을 처리할 때 좀 어렵다는거.옵션을 줘야한다.
위의 글에서 자세한 내용을 참고~
두번째 방법인 Low-Level JSON support
JSONObject나 JSONArray를 이용. Jettison project 를 이용
가장 큰 이점은 JSON format의 produced나 consumed을 full로 컨트롤할 수 있다. 직접 사용자가 원하는데로 쓰기때문에.. 반면에 data model object를 다룰때 JAXB기반보다는 좀더 복잡하다
간단한 JSON의 경우 JAXB를 쓸 경우엔 한줄로 끝나지만 JSONObject를 생성해서 쓰면 꽤 여러줄을 코딩해야 한다.
JAXB bean creation
MyJaxbBean myBean = new MyJaxbBean("Agamemnon", 32);
Constructing a JSONObject
JSONObject myObject = new JSONObject();
myObject.JSONObject myObject = new JSONObject();
try {
myObject.put("name", "Agamemnon");
myObject.put("age", 32);
} catch (JSONException ex) {
LOGGER.log(Level.SEVERE, "Error ...", ex);
}
간단한 경우엔 JAXB를..조금 섬세한 작업이 필요하다면 JSONObject를 쓰는것이 좋을 것 같다.
JAXB에서 configuration 설정은 지금보다 더 섬세한 작업을 할 수 있게 지원해준다면 좋을텐데...
참고!! 및 주의!!
그리고 현재 많이 보이는 글들중 JAXB를 조금 더 세세하게 옵션을 줘서 표현하는 방법에 ContextResolver<JAXBContext> 인터페이스를 구현하여 자신만의 JSONJAXBContext에 옵션을 주는 방법에
@Provider public class MyJAXBContextResolver implements ContextResolver<JAXBContext> { private JAXBContext context; private Class[] types = {StatusInfoBean.class, JobInfoBean.class}; public MyJAXBContextResolver() throws Exception { Map props = new HashMap<String, Object>(); props.put(JSONJAXBContext.JSON_NOTATION, JSONJAXBContext.JSONNotation.MAPPED); props.put(JSONJAXBContext.JSON_ROOT_UNWRAPPING, Boolean.TRUE); props.put(JSONJAXBContext.JSON_ARRAYS, new HashSet<String>(1){{add("jobs");}}); props.put(JSONJAXBContext.JSON_NON_STRINGS, new HashSet<String>(1){{add("pages"); add("tonerRemaining");}}); this.context = new JSONJAXBContext(types, props); } public JAXBContext getContext(Class<?> objectType) { return (types[0].equals(objectType)) ? context : null; } }
이런식으로 JSONJAXBContext.JSON_NOTATION 등의 상수들이 모두 deprecated 되었다.
Jersey 1.0.2 부터는 아래처럼 변경되었다.
@Provider public class MyJAXBContextResolver implements ContextResolver<JAXBContext> { private JAXBContext context; private Class[] types = {StatusInfoBean.class, JobInfoBean.class}; public MyJAXBContextResolver() throws Exception { this.context = new JSONJAXBContext( JSONConfiguration.mapped() .rootUnwrapping(true) .arrays("jobs") .nonStrings("pages", "tonerRemaining") .build(), types); } public JAXBContext getContext(Class<?> objectType) { return (types[0].equals(objectType)) ? context : null; } }
자세한 내용은 Japod의 블로그인 Configuring JSON for RESTful Web Services in Jersey 1.0.2 여기서 확인할 것!
'나만의 작업' 카테고리의 다른 글
| Jersey의 JSON Support (2) | 2009/06/08 |
|---|---|
| Jersey의 Exception Handling (0) | 2009/06/05 |
| Jersey의 Return Type (0) | 2009/06/04 |
| Jersey의 MessageBodyReader/Writer (0) | 2009/06/03 |
| JAX-RS @Produces와 @Consumes (2) | 2009/06/02 |
| JAX-RS의 구성 (0) | 2009/06/01 |
| What is Jersey? (0) | 2009/06/01 |
| What is JAX-RS? (0) | 2009/05/29 |
| What is REST? (2) | 2009/05/27 |
이올린에 북마크하기
이올린에 추천하기
