6월 16일 딱~ 하루하는 행사가 있군요.... :: 2009/06/16 13:45

우연히 RSS 리더를 읽다가 6월 16일 딱 하루만 하는 행사가 있어서 재미삼아 참여해 보았습니다.


"6월 16일, 내가 담는 하루가 역사가 된다 - e하루616" 





다음세대재단에서 주관하는 매일매일 다르게 변화하는 웹페이지를 하루동안 그 역사를 담는 타임캡슐처럼 담는 것입니다. 

자신이 올리고 싶은 웹페이지를 캡쳐해서 전송하여 미래에 2009년 6월 16일엔 어떤 웹페이지가 존재했었나 어떤 내용이었나를 확인할 수 있는 뜻깊은 행사 같아서 저도 한번 제 블로그를 올려보았습니다.

전시관에서는 작년 이때, 제작년 이때를 둘러볼 수도 있습니다.



블로그를 가지고 계신분이나, 남기고 싶은 웹페이지가 있다면 한번 올려보시는것도..
적긴 하지만 경품도 준다고 합니다. 
이올린에 북마크하기(0) 이올린에 추천하기(0)

  • BlogIcon 유야 | 2009/06/16 14:27 | PERMALINK | EDIT/DEL | REPLY

    ㅎㅎ 나도 오늘아침에 했는데 ㅋㅋ 쓸데없이 일찍일어나는 바람에 -_- 컴터 켰다가 한 5개 올렸어 ㅋ

    • BlogIcon 버리야 | 2009/06/17 11:49 | PERMALINK | EDIT/DEL

      와우 5개..ㅋㅋ 난 내꺼만 겨우 올렸는데..
      암튼 내년에 다시 조회해보면 변화한 사이트를 볼 수 있어서
      참 재미있을듯..

Name
Password
Homepage
Secret

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을 처리할 때 좀 어렵다는거.옵션을 줘야한다.

참고 : Jersey 1.0에서 RESTful 웹 서비스용 JSON 구성
위의 글에서 자세한 내용을 참고~


두번째 방법인 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;
       }
   }


JSON Configuration 이 달라졌음을 꼭 확인할것!! 

자세한 내용은 Japod의 블로그인 Configuring JSON for RESTful Web Services in Jersey 1.0.2 여기서 확인할 것! 



이올린에 북마크하기(0) 이올린에 추천하기(0)

'나만의 작업' 카테고리의 다른 글

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

  • [NC]...YellOw | 2009/06/10 21:10 | PERMALINK | EDIT/DEL | REPLY

    날이 점점 더워지고 있네요. 더위 조심하세요~~

Name
Password
Homepage
Secret
< PREV | 1|2|3|4|5| ... 169| NEXT >