[JAXB] JAXB Annotation 설명~ Part. 2

출처: http://www.caucho.com/resin-3.1/doc/jaxb-annotations.xtp

@XmlElements
다중 @XmlElement를 정의할 때 사용
super class의 sub class 들을 따로 관리할 때 사용하면 용의할 것 같음

01 class Bean {
02   @XmlElements({
03     @XmlElement(name="a",type=BeanA.class),
04     @XmlElement(name="b",type=BeanB.class)
05   })
06   private List<SubBean> data = new List<SubBean>();
07 }
08  
09 class BeanA extends SubBean {
10   @XmlValue
11   private String data;
12 }
13  
14 class BeanB extends SubBean {
15   @XmlValue
16   private String data;
17 }


XML Document

1 <Bean>
2   <a>Some BeanA Data</a>
3   <b>Some BeanB Data</b>
4   <a>Another BeanA Data</a>
5 </Bean>




@XmlElementWrapper
list 형식의 Element를 serialized 하기 위한 annotate

1 class Bean {
2   @XmlElementWrapper(name="values")
3   private List<String> data = new ArrayList<String>();
4 }


XML Document

1 <Bean>
2   <values>
3     <data>Some data</data>
4     <data>Another item</data>
5     <data>Third item</data>
6   </values>
7 </Bean>




@XmlJavaTypeAdapter
-_-;;;;;  설명하기에는 영어실력이 딸려서.. ㅠ_ㅠ
XmlAdapter를 이용해서 Java Type에 맞게 convert해주는 것을 정의하는 것 같음....

01 class Bean {
02   @XmlJavaTypeAdapter(MyMapAdapter.class)
03   private HashMap<String,String> map;
04 }
05  
06 class MyMapAdapter
07   extends XmlAdapter<Temp,Map<String,String>> {
08   ...
09 }
10  
11 class Temp {
12   @XmlElement
13   private List<Item> entry = new ArrayList<item>();
14 }
15  
16 class Item {
17   @XmlAttribute
18   private String key;
19  
20   @XmlAttribute
21   private String value;
22 }


XML Document

1 <Bean>
2   <entry key="a" value="data-a"/>
3   <entry key="b" value="data-b"/>
4   <entry key="c" value="data-c"/>
5 </Bean>




@XmlRootElement
xml에서 최상위 노드를 annotate.
하지만 하위노드에서도 사용을 한다.. 이유는???

경축! 아무것도 안하여 에스천사게임즈가 새로운 모습으로 재오픈 하였습니다.
어린이용이며, 설치가 필요없는 브라우저 게임입니다.
https://s1004games.com

1 @XmlRootElement(name="my-bean")
2 class Bean {
3   public String data;
4 }


XML Document

1 <my-bean>
2   <data>A sample value</data>
3 </my-bean>




@XmlTransient
unserialrizable을 mark.....
이걸 찾으려고 이 고생을... ㅠ_ㅠ XmlAccessorType.FIELD 로 해도 되는 거 였구나...

예제는 없습니다. ㅋㅋㅋ


@XmlValue
하나의 property나 field만 있을 경우 해당 property나 field에 serialized.

1 class Bean {
2   @XmlValue
3   private String data;
4 }


XML Document

1 <Bean>Sample Data</Bean>

 



출처: https://vicki.tistory.com/21 [불친절한자수씨]

 

 

본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
번호 제목 글쓴이 날짜 조회 수
309 Learn Eclipse GMF in 15 minutes file 졸리운_곰 2019.11.20 94
308 RCP 에디터 정리 졸리운_곰 2019.11.20 175
307 다른 그림과 관련하여 GEF 편집기 레이아웃에서 그림의 위치 제한 조건을 동적으로 계산 Dynamically calculating the position constraints for a figure in a GEF editor layout in relation to another figure file 졸리운_곰 2019.11.20 148
306 추상(abstract) 클래스가 필요한 기본적인 이유 졸리운_곰 2019.10.30 136
305 Java Byte Array to InputStream 졸리운_곰 2019.10.24 76
» [JAXB] JAXB Annotation 설명~ Part. 2 졸리운_곰 2019.10.24 208
303 [JAXB] JAXB Annotation 설명~ Part. 1 졸리운_곰 2019.10.24 64
302 JAXB (3) - marshal, unmarshal에 대해 알아보자. file 졸리운_곰 2019.10.24 66
301 JAXB (2) - XML Schema를 Java Interfaces & Classes로 Binding Compile 하기 file 졸리운_곰 2019.10.24 65
300 JAXB (1) - JAXB 란? file 졸리운_곰 2019.10.24 80
299 XStream으로 자바 객체를 XML로 직렬화하기 file 졸리운_곰 2019.10.15 143
298 [번역] XStream 배우기 : 2분만에 배우는 XStream 졸리운_곰 2019.10.15 160
297 RCP 등에서 .mf 파일로 다른 프로젝트 익스포트 포함시 라이브러리(메소드)를 찾지 못할 때, Eclipse RCP - cant resolve importing libraries in final build file 졸리운_곰 2019.10.15 252
296 java XML Parser 정리 졸리운_곰 2019.10.05 92
295 ESE2006-EclipseModelingSymposium15_GMF.pdf file 졸리운_곰 2019.09.21 122
294 GMF_Creation_Review.pdf file 졸리운_곰 2019.09.21 116
293 Eclipse EMF and GMF Tutorial file 졸리운_곰 2019.09.21 77
292 GMF Tutorial/ko file 졸리운_곰 2019.09.20 214
291 Model Driven Architecture approach to domain of graphical editors file 졸리운_곰 2019.09.20 110
290 org.eclipse.ui.navigator Class CommonViewer 졸리운_곰 2019.07.04 107
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED