티스토리 뷰
1. REST에서 xml를 서버스하는 것은 간단하지만 xml서비스를 위한 스키마 작성은 조금 해야 할 것이 있다.
2. 우선 xsd를 작성해야 하는데 그냥 하기에는 조금 부담스럽기 때문에 generator로 작성하면 좀 편하다
Free Online XSD/XML Schema Generator - FreeFormatter.com
XSD/XML Schema Generator Generates a XSD (XML Schema) from a XML file. Simply copy-paste OR upload your XML document and let the generator figure out the rest. The generator will try to use a 'smart' approach to figure out the data type (you can always ref
www.freeformatter.com
2-1 위의 링크에 가서 우선 jackson-xml를 결과를 가지고 생성한 결과를 사용한다.
2-2 아래와 비슷한 내용의 파일이 생성되면 열어서 적절하게 수정하면 된다.
2-2-1 CustomerListDTO 아래 Customers 아래 Customer 리스트가 들어가게 하려고 했는데 잘되지 않는다.
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="CustomerListDTO" type="CustomerListDTO"/>
<xs:complexType name="CustomerDTO">
<xs:sequence>
<xs:element type="xs:string" name="firstname" minOccurs="0"/>
<xs:element type="xs:string" name="lastname" minOccurs="0"/>
<xs:element type="xs:string" name="customerUrl" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="CustomerListDTO">
<xs:sequence>
<xs:element type="CustomerDTO" name="customers" maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
3 위의 소스를 customers.xsd로 이름을 바꾸어 src/main/resources/xsd/ 아래에 저장한다.
4. codehaus 사이트에 가면 jaxb2-maven-plugin에 대한 pom 코드를 받을 수 있다.
JAXB-2 Maven Plugin – Basic Examples - Java Generation
Basic Examples - Java Generation Note: These examples are valid for the 2.x version of the plugin, and do not necessarily work for the jaxb2-maven-plugin version 1.x These basic examples show how to generate Java code from JAXB using the jaxb2-maven-plugin
www.mojohaus.org
4-1 위의 사이트에 있는 코드를 참고하여 XML용 model 생성용 플러인을 pom에 작성한다.
4-1-1 packageName는 생성된 클래스의 package 이름이 될 정보이다.
4-1-2 sources에는 현재 xsd가 어디에 저장되어 있는지를 지정한다.
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.5.0</version>
<executions>
<execution>
<id>xjc</id>
<goals>
<goal>xjc</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- The package of your generated sources -->
<packageName>pe.pilseong.restdemo.model</packageName>
<sources>src/main/resources/xsd</sources>
</configuration>
</plugin>
</plugins>
</build>
4-2 위 처럼 설정하고 컴파일을 하거나 xsd를 저장하면 아래처럼 자동으로 xsd에 따른 클래스 소스가 생성된다.
5. 실행 결과
5-1 customers 아래 customer가 들어가야 하는데 xsd에 대해서 대강 눈으로 배워 생각처럼 되지 않는다.
5-1-1 다음에 해결책을 찾으면 붙여 줄 예정
'Spring > Spring REST' 카테고리의 다른 글
Spring REST : Richardson Maturity Model (0) | 2021.05.05 |
---|---|
Spring REST : Spring REST Docs 사용하기 (0) | 2020.09.18 |
Spring REST : XML REST 서비스 지원하기 (0) | 2020.09.16 |
Spring REST : OpenAPI 3.0 설정 (0) | 2020.09.05 |
Spring REST : Swagger2 설정하기 (0) | 2020.09.04 |
- Total
- Today
- Yesterday
- 도커 개발환경 참고
- AWS ARN 구조
- Immuability에 관한 설명
- 자바스크립트 멀티 비동기 함수 호출 참고
- WSDL 참고
- SOAP 컨슈머 참고
- MySql dump 사용법
- AWS Lambda with Addon
- NFC 드라이버 linux 설치
- electron IPC
- mifare classic 강의
- go module 관련 상세한 정보
- C 메모리 찍어보기
- C++ Addon 마이그레이션
- JAX WS Header 관련 stackoverflow
- SOAP Custom Header 설정 참고
- SOAP Custom Header
- SOAP BindingProvider
- dispatcher 사용하여 설정
- vagrant kvm으로 사용하기
- git fork, pull request to the …
- vagrant libvirt bridge network
- python, js의 async, await의 차이
- go JSON struct 생성
- Netflix Kinesis 활용 분석
- docker credential problem
- private subnet에서 outbound IP 확…
- 안드로이드 coroutine
- kotlin with, apply, also 등
- 안드로이드 초기로딩이 안되는 경우
- navigation 데이터 보내기
- 레이스 컨디션 navController
- raylib
- 설정
- one-to-one
- 매핑
- login
- mapping
- Spring Security
- spring boot
- Angular
- 스프링부트
- jsp
- Spring
- Security
- Many-To-Many
- RestTemplate
- 스프링
- 설정하기
- Rest
- one-to-many
- 자바
- 상속
- crud
- MYSQL
- form
- 로그인
- 외부파일
- 하이버네이트
- hibernate
- XML
- Validation
- WebMvc