[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 [불친절한자수씨]

 

 

본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
번호 제목 글쓴이 날짜 조회 수
38 Spring Batch 간단 정리 Sprong Batch 기초를 알아보자 file 졸리운_곰 2020.10.13 198
37 Spring Batch - ItemReader, ItemWriter, ItemProcessor 졸리운_곰 2020.10.13 370
36 spring batch» Spring Batch Tasklet Example file 졸리운_곰 2020.10.12 198
35 Spring Batch Example 2 - 간단한 Job만들기 file 졸리운_곰 2020.10.12 151
34 Spring batch Job 설정과 실행하기 file 졸리운_곰 2020.10.12 206
33 [Spring Batch] Configuring and Running a Job file 졸리운_곰 2020.10.12 121
32 [스프링] 스프링 배치 기본 개념 file 졸리운_곰 2019.12.24 244
31 Spring Batch 개념 정리 file 졸리운_곰 2019.12.24 258
30 스프링 배치 개발가이드 졸리운_곰 2019.12.24 321
29 Quartz + Spring Batch 조합! Quartz Scheduler 와 Spring Batch 의 궁합과 조합을 정리. file 졸리운_곰 2019.12.24 882
28 Spring Batch 간단 정리 file 졸리운_곰 2019.12.24 422
27 spring batch 소개 file 졸리운_곰 2019.12.24 210
26 Spring Batch - 소개 file 졸리운_곰 2019.12.24 207
25 Spring Batch Multithreading Example file 졸리운_곰 2019.01.31 285
24 Spring batch를 Parallel로 돌려보자 졸리운_곰 2019.01.31 399
23 Spring MVC 주요 애노테이션(Annotation)정리 file 졸리운_곰 2018.12.29 269
22 스프링/스프링부트 애노테이션(Annotation) 정리 졸리운_곰 2018.12.29 385
21 Spring Framework - annotation 정리 #1 졸리운_곰 2018.12.29 321
20 [Spring] Annotation 정리 졸리운_곰 2018.12.29 272
19 Maven 기초 사용법 졸리운_곰 2018.04.15 322
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED