{"id":1212,"date":"2013-03-05T18:16:00","date_gmt":"2013-03-05T18:16:00","guid":{"rendered":"http:\/\/brain.payzip.co.kr\/?p=1212"},"modified":"2013-03-05T18:16:00","modified_gmt":"2013-03-05T18:16:00","slug":"jaxb%eb%9e%80","status":"publish","type":"post","link":"https:\/\/blog.goorigo.com\/?p=1212","title":{"rendered":"JAXB\ub780?"},"content":{"rendered":"<h1>\uc790\ubc146 \uc774\uc0c1\uc744 \uc0ac\uc6a9\ud558\ub294 \ubcc4\ub2e4\ub978JAR\uc5c6\uc774 \ub77c\uc774\ube0c\ub7ec\ub9ac\ub97c \uc0ac\uc6a9\ud560\uc218\uc788\ub2e4\uace0\ud55c\ub2e4.<\/h1>\n<p>&nbsp;<\/p>\n<h1><\/h1>\n<h1><a href=\"http:\/\/choyeonseop.blogspot.com\/2013\/02\/1-jaxb-jaxb.html\" rel=\"bookmark\">1. JAXB\ub780 \ubb34\uc5c7\uc778\uac00? JAXB\uc758 \uc124\uc815\uacfc \ud29c\ud1a0\ub9ac\uc5bc<\/a><\/h1>\n<div>\n<div><strong>1. JAXB (Java Architecture for XML Binding)<\/strong><strong>\ub780<\/strong><strong>?<\/strong><\/div>\n<div><\/div>\n<div>\u00a0 &#8211; XML\u00a0\uc2a4\ud0a4\ub9c8 \ub370\uc774\ud130\ub97c\u00a0JAVA CLASS \ud615\ud0dc\ub85c\u00a0\ub9cc\ub4e4 \uc218 \uc788\uc2b5\ub2c8\ub2e4. Marshalling(Serialization)<\/div>\n<div>\u00a0 &#8211; \ubc18\ub300\ub85c\u00a0Java Class\ub97c\u00a0XML\u00a0\ub370\uc774\ud130\ub85c \ub9cc\ub4e4 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<\/div>\n<div>\u00a0 \u00a0 \u00a0\uc989,\u00a0JAXB\ub97c \uc774\uc6a9\ud55c\u00a0XML\u00a0\uc9c1\ub82c\ud654\u00a0Unmarshalling(Deserialization)<\/div>\n<div><\/div>\n<div><strong>2. \ud658\uacbd \uad6c\uc131<\/strong><\/div>\n<div><strong>\u00a0\u00a0<\/strong><\/div>\n<div><strong>\u00a0 &#8211;\u00a0<\/strong>JAXB\ub294 JDK 1.6 \uc774\uc0c1\uc744 \uc694\uad6c\ud558\uace0 \uc788\uc2b5\ub2c8\ub2e4.<\/div>\n<div><strong><br \/>\n<\/strong><\/div>\n<div><strong>3. JAXB\uc758 Annotation\uc758 \uad6c\uc131<\/strong><br \/>\n<strong><br \/>\n<\/strong>@XmlRootElement(namespace = &#8220;namespace&#8221;) : \ucd5c\uc0c1\uc704 \uc694\uc18c\ub97c \uc815\uc758\ud569\ub2c8\ub2e4.<\/p>\n<p>@XmlType(propOrder = { &#8220;field2&#8221;, &#8220;field1&#8221;,.. }) : XML \ud544\ub4dc \uad6c\uc131\uc744 \uc815\uc758\ud569\ub2c8\ub2e4.<\/p>\n<p>@XmlElement(name = &#8220;neuName&#8221;) : XML\u00a0\ud544\ub4dc \uc694\uc18c\ub97c \uc815\uc758 \ud569\ub2c8\ub2e4.<\/p>\n<\/div>\n<div><strong><br \/>\n<\/strong><\/div>\n<div><strong>4. \uc18c\uc2a4 \uc124\uc815<\/strong><br \/>\n<strong><br \/>\n<\/strong><\/div>\n<div>\n<strong>&#8211; \uc6b0\uc120\uc801\uc73c\ub85c \ucc45(Book)\uc774\ub780 Class\ub97c \ub9cc\ub4e4\uc5b4 \ubcf4\uaca0\uc2b5\ub2c8\ub2e4.<\/strong><\/p>\n<table>\n<tbody>\n<tr>\n<td>package de.vogella.xml.jaxb.model;<\/p>\n<p>import javax.xml.bind.annotation.XmlElement;<br \/>\nimport javax.xml.bind.annotation.XmlRootElement;<br \/>\nimport javax.xml.bind.annotation.XmlType;<\/p>\n<p>@XmlRootElement(name = &#8220;book&#8221;)<br \/>\n\/\/ If you want you can define the order in which the fields are written<br \/>\n\/\/ Optional<br \/>\n@XmlType(propOrder = { &#8220;author&#8221;, &#8220;name&#8221;, &#8220;publisher&#8221;, &#8220;isbn&#8221; })<br \/>\npublic class Book {<\/p>\n<p>private String name;<br \/>\nprivate String author;<br \/>\nprivate String publisher;<br \/>\nprivate String isbn;<\/p>\n<p>\/\/ If you like the variable name, e.g. &#8220;name&#8221;, you can easily change this<br \/>\n\/\/ name for your XML-Output:<br \/>\n@XmlElement(name = &#8220;title&#8221;)<br \/>\npublic String getName() {<br \/>\nreturn name;<br \/>\n}<\/p>\n<p>public void setName(String name) {<br \/>\nthis.name = name;<br \/>\n}<\/p>\n<p>public String getAuthor() {<br \/>\nreturn author;<br \/>\n}<\/p>\n<p>public void setAuthor(String author) {<br \/>\nthis.author = author;<br \/>\n}<\/p>\n<p>public String getPublisher() {<br \/>\nreturn publisher;<br \/>\n}<\/p>\n<p>public void setPublisher(String publisher) {<br \/>\nthis.publisher = publisher;<br \/>\n}<\/p>\n<p>public String getIsbn() {<br \/>\nreturn isbn;<br \/>\n}<\/p>\n<p>public void setIsbn(String isbn) {<br \/>\nthis.isbn = isbn;<br \/>\n}<\/p>\n<p>}<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>&#8211; \ucc45\uc744 \uc0ac\uae30 \uc704\ud574\uc11c\ub294 \uc11c\uc810\uc774 \ud544\uc694\ud558\ubbc0\ub85c BookStore\ub97c \ub9cc\ub4e4\uc5b4 \ubcf4\uaca0\uc2b5\ub2c8\ub2e4.<\/strong><br \/>\n<strong><br \/>\n<\/strong><\/p>\n<table>\n<tbody>\n<tr>\n<td>package de.vogella.xml.jaxb.model;<\/p>\n<p>import java.util.ArrayList;<\/p>\n<p>import javax.xml.bind.annotation.XmlElement;<br \/>\nimport javax.xml.bind.annotation.XmlElementWrapper;<br \/>\nimport javax.xml.bind.annotation.XmlRootElement;<\/p>\n<p>\/\/This statement means that class &#8220;Bookstore.java&#8221; is the root-element of our example<br \/>\n@XmlRootElement(namespace = &#8220;de.vogella.xml.jaxb.model&#8221;)<br \/>\npublic class Bookstore {<\/p>\n<p>\/\/ XmLElementWrapper generates a wrapper element around XML representation<br \/>\n@XmlElementWrapper(name = &#8220;bookList&#8221;)<br \/>\n\/\/ XmlElement sets the name of the entities<br \/>\n@XmlElement(name = &#8220;book&#8221;)<br \/>\nprivate ArrayList&lt;Book&gt; bookList;<br \/>\nprivate String name;<br \/>\nprivate String location;<\/p>\n<p>public void setBookList(ArrayList&lt;Book&gt; bookList) {<br \/>\nthis.bookList = bookList;<br \/>\n}<\/p>\n<p>public ArrayList&lt;Book&gt; getBooksList() {<br \/>\nreturn bookList;<br \/>\n}<\/p>\n<p>public String getName() {<br \/>\nreturn name;<br \/>\n}<\/p>\n<p>public void setName(String name) {<br \/>\nthis.name = name;<br \/>\n}<\/p>\n<p>public String getLocation() {<br \/>\nreturn location;<br \/>\n}<\/p>\n<p>public void setLocation(String location) {<br \/>\nthis.location = location;<br \/>\n}<br \/>\n}<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div><\/div>\n<div>\uc989, \uc11c\uc810\uc758 \uc694\uc18c\uc5d0\ub294 \ubd81\uc774 \ud3ec\ud568\ub418\uc5b4 \uc788\ub2e4\uace0 \uc0dd\uac01 \ud558\uc2dc\uba74 \ub418\uc2dc\uaca0\uc2b5\ub2c8\ub2e4. (\ubd81 &lt; \uc11c\uc810)<\/div>\n<div><\/div>\n<div>\uc774\uc81c \uc774\ub7f0 Book XML \uad00\uacc4\ub3c4\ub97c XML \ud30c\uc77c\ub85c \ucd9c\ub825\ud558\ub294 main \ud074\ub798\uc2a4\ub97c \ub9cc\ub4e4\uc5b4 \ubcf4\uaca0\uc2b5\ub2c8\ub2e4.<\/div>\n<div><\/div>\n<table>\n<tbody>\n<tr>\n<td>\npackage test;<\/p>\n<p>import java.io.File;<br \/>\nimport java.io.FileReader;<br \/>\nimport java.io.IOException;<br \/>\nimport java.util.ArrayList;<\/p>\n<p>import javax.xml.bind.JAXBContext;<br \/>\nimport javax.xml.bind.JAXBException;<br \/>\nimport javax.xml.bind.Marshaller;<br \/>\nimport javax.xml.bind.Unmarshaller;<\/p>\n<p>import de.vogella.xml.jaxb.model.Book;<br \/>\nimport de.vogella.xml.jaxb.model.Bookstore;<\/p>\n<p>public class BookMain {<\/p>\n<p>private static final String BOOKSTORE_XML = &#8220;.\/bookstore-jaxb.xml&#8221;;<\/p>\n<p>public static void main(String[] args) throws JAXBException, IOException {<\/p>\n<p>ArrayList&lt;Book&gt; bookList = new ArrayList&lt;Book&gt;();<\/p>\n<p>\/\/ create books<br \/>\nBook book1 = new Book();<br \/>\nbook1.setIsbn(&#8220;978-0060554736&#8221;);<br \/>\nbook1.setName(&#8220;The Game&#8221;);<br \/>\nbook1.setAuthor(&#8220;Neil Strauss&#8221;);<br \/>\nbook1.setPublisher(&#8220;Harpercollins&#8221;);<br \/>\nbookList.add(book1);<\/p>\n<p>Book book2 = new Book();<br \/>\nbook2.setIsbn(&#8220;978-3832180577&#8221;);<br \/>\nbook2.setName(&#8220;Feuchtgebiete&#8221;);<br \/>\nbook2.setAuthor(&#8220;Charlotte Roche&#8221;);<br \/>\nbook2.setPublisher(&#8220;Dumont Buchverlag&#8221;);<br \/>\nbookList.add(book2);<\/p>\n<p>\/\/ create bookstore, assigning book<br \/>\nBookstore bookstore = new Bookstore();<br \/>\nbookstore.setName(&#8220;Fraport Bookstore&#8221;);<br \/>\nbookstore.setLocation(&#8220;Frankfurt Airport&#8221;);<br \/>\nbookstore.setBookList(bookList);<\/p>\n<p>\/\/ create JAXB context and instantiate marshaller<br \/>\nJAXBContext context = JAXBContext.newInstance(Bookstore.class);<br \/>\nMarshaller m = context.createMarshaller();<br \/>\nm.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);<\/p>\n<p>\/\/ Write to System.out<br \/>\nm.marshal(bookstore, System.out);<\/p>\n<p>\/\/ Write to File<br \/>\nm.marshal(bookstore, new File(BOOKSTORE_XML));<\/p>\n<p>\/\/ get variables from our xml file, created before<br \/>\nSystem.out.println();<br \/>\nSystem.out.println(&#8220;Output from our XML File: &#8220;);<br \/>\nUnmarshaller um = context.createUnmarshaller();<br \/>\nBookstore bookstore2 = (Bookstore) um.unmarshal(new FileReader(BOOKSTORE_XML));<br \/>\nArrayList&lt;Book&gt; list = bookstore2.getBooksList();<br \/>\nfor (Book book : list) {<br \/>\nSystem.out.println(&#8220;Book: &#8221; + book.getName() + &#8221; from &#8221;<br \/>\n+ book.getAuthor());<br \/>\n}<br \/>\n}<br \/>\n}<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>5. \uc2e4\uc81c \uad6c\ub3d9 \ud654\uba74<\/strong><br \/>\n<strong><br \/>\n<\/strong><strong>&#8211; \ud30c\uc77c \ubc0f \ub514\ub809\ud1a0\ub9ac \uad6c\uc131\ub3c4 \uc785\ub2c8\ub2e4.<\/strong><br \/>\n<strong><br \/>\n<\/strong><\/p>\n<div><\/div>\n<p><strong><br \/>\n<\/strong><\/p>\n<p><strong>&#8211; \ud30c\uc77c\uc744 \uc791\uc131\ud569\ub2c8\ub2e4.<\/strong><\/p>\n<div><\/div>\n<div><\/div>\n<div><\/div>\n<p>&#8211;\u00a0<strong>\uc790\ubc14 Main Class\ub85c \ucd9c\ub825\uc744 \uc2dc\ucf1c \ubd05\ub2c8\ub2e4.<\/strong><\/p>\n<div><\/div>\n<p><strong><br \/>\n<\/strong><\/p>\n<p><strong>6. \ucc38\uace0 URL<\/strong><\/p>\n<div><a href=\"http:\/\/www.vogella.com\/articles\/JAXB\/article.html\">http:\/\/www.vogella.com\/articles\/JAXB\/article.html<\/a>\u00a0(JAXB \ud29c\ud1a0\ub9ac\uc5bc)<\/div>\n<\/div>\n<div><\/div>\n<\/div>\n<div><\/div>\n<div>\ucd9c\ucc98 :\u00a0http:\/\/choyeonseop.blogspot.kr\/2013\/02\/1-jaxb-jaxb.html<\/div>\n<div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\uc790\ubc146 \uc774\uc0c1\uc744 \uc0ac\uc6a9\ud558\ub294 \ubcc4\ub2e4\ub978JAR\uc5c6\uc774 \ub77c\uc774\ube0c\ub7ec\ub9ac\ub97c \uc0ac\uc6a9\ud560\uc218\uc788\ub2e4\uace0\ud55c\ub2e4. &nbsp; 1. JAXB\ub780 \ubb34\uc5c7\uc778\uac00? JAXB\uc758 \uc124\uc815\uacfc \ud29c\ud1a0\ub9ac\uc5bc 1. JAXB (Java Architecture for XML Binding)\ub780? \u00a0 &#8211; XML\u00a0\uc2a4\ud0a4\ub9c8 \ub370\uc774\ud130\ub97c\u00a0JAVA CLASS \ud615\ud0dc\ub85c\u00a0\ub9cc\ub4e4 \uc218 \uc788\uc2b5\ub2c8\ub2e4. Marshalling(Serialization) \u00a0&hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.goorigo.com\/index.php?rest_route=\/wp\/v2\/posts\/1212"}],"collection":[{"href":"https:\/\/blog.goorigo.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.goorigo.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.goorigo.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.goorigo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1212"}],"version-history":[{"count":0,"href":"https:\/\/blog.goorigo.com\/index.php?rest_route=\/wp\/v2\/posts\/1212\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.goorigo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1212"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.goorigo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1212"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.goorigo.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1212"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}