{"id":10815,"date":"2014-06-25T14:40:33","date_gmt":"2014-06-25T11:40:33","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=10815"},"modified":"2014-07-29T15:51:31","modified_gmt":"2014-07-29T12:51:31","slug":"jaxb-unmarshal-example","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-unmarshal-example\/","title":{"rendered":"JAXB unmarshal example"},"content":{"rendered":"<p>In my last <a href=\"http:\/\/examples.javacodegeeks.com\/core-java\/xml\/bind\/jaxb-marshal-example\/\">article<\/a>, I&#8217;ve explained how to marshall java objects to xml using JAXB. In this one, we are going to see how to do the complementary operation: unmarshal xml files into java objects and what should be taken into consideration while doing this operation.<\/p>\n<p>For this purpose we are going to use the same example as in the <a href=\"http:\/\/examples.javacodegeeks.com\/core-java\/xml\/bind\/jaxb-marshal-example\/\">marshal example article<\/a>. We are going to unmarshall an xml containing information about a list of museums with its main exhibitions and artists exposed.<\/p>\n<p>The java version used for these examples is the JRE 1.8.0. The IDE used is Eclipse SDK Version: Luna (4.4) but the code should work in any other IDE supporting java.<\/p>\n<p>The code shown bellow unmarshalls a given xml file into java objects. The classes of these objects should contain a set of attributes and annotations:<\/p>\n<h2>XML file:<\/h2>\n<pre class=\"brush:xml\">&lt;?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?&gt;\r\n&lt;MUSEUMS&gt;\r\n &lt;MUSEUM children_allowed=\"false\"&gt;\r\n   &lt;MUSEUM_NAME&gt;Reina Sofia Museum&lt;\/MUSEUM_NAME&gt;\r\n   &lt;CITY&gt;Madrid&lt;\/CITY&gt;\r\n   &lt;PERMANENT_EXHIBITION&gt;\r\n      &lt;NAME&gt;Permanent Exhibition - Reina Sofia Museum&lt;\/NAME&gt;\r\n      &lt;ARTIST&gt;Picasso&lt;\/ARTIST&gt;\r\n      &lt;ARTIST&gt;Dali&lt;\/ARTIST&gt;\r\n      &lt;ARTIST&gt;Miro&lt;\/ARTIST&gt;\r\n      &lt;FROM&gt;1900-01-01&lt;\/FROM&gt;\r\n      &lt;TO&gt;2014-12-31&lt;\/TO&gt;\r\n   &lt;\/PERMANENT_EXHIBITION&gt;\r\n &lt;\/MUSEUM&gt;\r\n &lt;MUSEUM&gt;\r\n   &lt;MUSEUM_NAME&gt;Louvre Museum&lt;\/MUSEUM_NAME&gt;\r\n   &lt;CITY&gt;Paris&lt;\/CITY&gt;\r\n   &lt;PERMANENT_EXHIBITION&gt;\r\n      &lt;NAME&gt;Permanent Exhibition - Louvre Museum&lt;\/NAME&gt;\r\n      &lt;ARTIST&gt;Leonardo da Vinci&lt;\/ARTIST&gt;\r\n      &lt;ARTIST&gt;Caravaggio&lt;\/ARTIST&gt;\r\n      &lt;ARTIST&gt;Delacroix&lt;\/ARTIST&gt;\r\n   &lt;\/PERMANENT_EXHIBITION&gt;\r\n &lt;\/MUSEUM&gt;\r\n&lt;\/MUSEUMS&gt;\r\n<\/pre>\n<h2>and the Java main program:<\/h2>\n<pre class=\"brush:java\">\t\tFile file = new File(\"museums.xml\");\r\n\t\tJAXBContext jaxbContext = JAXBContext.newInstance(Museums.class);\r\n\t\tUnmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();\r\n\t\tMuseums museums = (Museums) jaxbUnmarshaller.unmarshal(file);\r\n\t\tSystem.out.println(museums);\r\n<\/pre>\n<p>The output produced would be something like:<\/p>\n<pre class=\"brush:bash\">Name: Prado Museum\r\nCity: Madrid\r\nPermanent Exhibition - Prado Museum\r\nGame of Bowls (1908), by Henri Matisse\r\n\r\nName: Reina Sofia Museum\r\nCity: Madrid\r\nATTENTION! Children are not allowed in this museum\r\nPermanent Exhibition - Reina Sofia Museum\r\n\r\nName: British Museum\r\nCity: London\r\nPermanent Exhibition - British Museum\r\n\r\nName: MOMA\r\nCity: New York\r\nPermanent Exhibition - MOMA\r\n\r\nName: Louvre Museum\r\nCity: Paris\r\nPermanent Exhibition - Louvre Museum\r\n<\/pre>\n<p>but this depends in the current Java code handling the <code>Museums<\/code> class.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>The method <code>createUnmarshaller<\/code> of the class <code>JAXBContext<\/code> creates an instance of the type <code>Unmarshaller<\/code> that allows us to proceed with our tasks. If the class <code>Museums<\/code> and its members are properly configured using the right JAXB annotations and field members, everything should work fine.<\/p>\n<p>The museums class contains a list of Museum items:<\/p>\n<pre class=\"brush:java\">@XmlRootElement( name = \"MUSEUMS\" )\r\npublic class Museums\r\n{\r\n    List museums;\r\n\r\n    \/**\r\n     * element that is going to be marshaled in the xml\r\n     *\/\r\n    @XmlElement( name = \"MUSEUM\" )\r\n    public void setMuseums( List museums )\r\n    {\r\n        this.museums = museums;\r\n    }\r\n...\r\n<\/pre>\n<p>and the Museum class contains fields that can be XML elements like the name or the city or XML attributes like the children allowance. These fields can be of any JAXB supported type:<\/p>\n<pre class=\"brush:java\">@XmlType( propOrder = { \"name\", \"city\", \"permanent\", \"special\" } )\r\n@XmlRootElement( name = \"MUSEUM\" )\r\npublic class Museum\r\n{\r\n    String name;\r\n\r\n    @XmlElement( name = \"MUSEUM_NAME\" )\r\n    public void setName( String name )\r\n    {\r\n        this.name = name;\r\n    }\r\n\r\n    Boolean childrenAllowed;\r\n\r\n    @XmlAttribute( name = \"children_allowed\")\r\n    public void setChildrenAllowed( Boolean childrenAllowed )\r\n    {\r\n        this.childrenAllowed = childrenAllowed;\r\n    }\r\n\r\n    Exhibition special;\r\n\r\n    @XmlElement( name = \"SPECIAL_EXHIBITION\" )\r\n    public void setSpecial( Exhibition special )\r\n    {\r\n        this.special = special;\r\n    }\r\n...\r\n<\/pre>\n<p>In case we want to use a field of a non supported type we have to implement ourselves an Adapter that indicates JAXB how to manage this kind of objects. This adapter extends the <code>XmlAdapter<\/code> class and implements its <code>marshal<\/code> and <code>unmarshal<\/code> methods:<\/p>\n<pre class=\"brush:java\">\t\r\npublic class LocalDateAdapter extends XmlAdapter\r\n{\r\n\r\n    public LocalDate unmarshal( String v ) throws Exception\r\n    {\r\n        return LocalDate.parse( v );\r\n    }\r\n\r\n    public String marshal( LocalDate v ) throws Exception\r\n    {\r\n        return v.toString();\r\n    }\r\n}\r\n<\/pre>\n<p>This adapter is used in the following way:<\/p>\n<pre class=\"brush:java\">\t\r\n    @XmlJavaTypeAdapter( LocalDateAdapter.class )\r\n    @XmlElement( name = \"FROM\" )\r\n    public void setFrom( LocalDate from )\r\n    {\r\n        this.from = from;\r\n    }\r\n<\/pre>\n<h2>Main annotations used<\/h2>\n<p>We are going to see some important points related to the configuration of the used classes and the annotations used to configure JAXB:<\/p>\n<p><code>@XmlRootElement<\/code>: This annotation binds an XML node with a class or an enum. In our example we bind, using the <code>@XmlRootElement<\/code>, the XML element &lt;MUSEUMS&gt;&#8230;&lt;\/MUSEUMS&gt; with the class Museums by annotating this class with <code>@XmlRootElement( name = \"MUSEUMS\" )<\/code>.<br \/>\nFor more information about this annotation please refer to <a href=\"http:\/\/docs.oracle.com\/javase\/7\/docs\/api\/javax\/xml\/bind\/annotation\/XmlRootElement.html\">XMLRootElement<\/a><\/p>\n<p><code>@XmlElement<\/code>: Maps XML node into a non static field of a class. In our example, among others, we map the element &lt;MUSEUM_NAME&gt;Prado Museum&lt;\/MUSEUM_NAME&gt; with the field name of the class <code>Museum<\/code> using the annotation <code>@XmlElement( name = \"MUSEUM_NAME\" )<\/code> in the <code>setName()<\/code> method.<br \/>\nFor more information about this one, please refer to <a href=\"http:\/\/docs.oracle.com\/javase\/7\/docs\/api\/index.html?javax\/xml\/bind\/annotation\/XmlElement.html\">XMLElement<\/a>.<\/p>\n<p><code>@XmlAttribute<\/code>: This annotation maps an XML attribute with a non static field of a class. We bind the childrenAllowed field of the Museum class with the xml attribute &lt;MUSEUM children_allowed=&#8221;false&#8221;&gt; using the following code:<\/p>\n<pre class=\"brush:java\">    @XmlAttribute( name = \"children_allowed\" )\r\n    public void setChildrenAllowed( Boolean childrenAllowed )\r\n    {\r\n        this.childrenAllowed = childrenAllowed;\r\n    }\r\n<\/pre>\n<p>For more information about the annotation <code>@XmlAttribute<\/code> go to <a href=\"http:\/\/docs.oracle.com\/javaee\/7\/api\/javax\/xml\/bind\/annotation\/XmlAttribute.html\">XMLAttribute<\/a>.<\/p>\n<p>And this is how we can unmarshal an XML file into Java objects.<\/p>\n<p>JAXB offers several ways to marshal and un marshal collections. In our example, we just created a Museums class that contains a list of Museum items, so JAXB can manage directly this class by simply using the annotations explained above. It is also possible to achieve something similar by using the annotations <code>@XmlElementWrapper<\/code> or <code>@XmlList<\/code>, but under my point of view, these ones are more complicated, offer less options and ties you in several ways in your class modelling.<\/p>\n<p>As already mentioned in the <a href=\"http:\/\/examples.javacodegeeks.com\/core-java\/xml\/bind\/jaxb-marshal-example\/\">article<\/a>, it is also possible to generate java classes with JAXB annotations automatically by using XSD (XML Schmema Definition). This offers also the possibility to validate the XML files against the provided XML Schema that we want to unmarshall. It is also important to mention that JAXB does not need an XSD to work (as we saw in this example), this offers Java programmers a lot of flexibility.<\/p>\n<p>All the code explained in this article and some running examples can be found in the following link: <a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/06\/unmarshall.zip\">unmarshall.zip<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In my last article, I&#8217;ve explained how to marshall java objects to xml using JAXB. In this one, we are going to see how to do the complementary operation: unmarshal xml files into java objects and what should be taken into consideration while doing this operation. For this purpose we are going to use the &hellip;<\/p>\n","protected":false},"author":21,"featured_media":1204,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[391],"tags":[],"class_list":["post-10815","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-bind"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>JAXB unmarshal example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"In my last article, I&#039;ve explained how to marshall java objects to xml using JAXB. In this one, we are going to see how to do the complementary operation:\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-unmarshal-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JAXB unmarshal example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"In my last article, I&#039;ve explained how to marshall java objects to xml using JAXB. In this one, we are going to see how to do the complementary operation:\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-unmarshal-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2014-06-25T11:40:33+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2014-07-29T12:51:31+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Dani Buiza\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Dani Buiza\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-unmarshal-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-unmarshal-example\/\"},\"author\":{\"name\":\"Dani Buiza\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/ee0f431dd55475919f56a8b41e52b219\"},\"headline\":\"JAXB unmarshal example\",\"datePublished\":\"2014-06-25T11:40:33+00:00\",\"dateModified\":\"2014-07-29T12:51:31+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-unmarshal-example\/\"},\"wordCount\":652,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-unmarshal-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"articleSection\":[\"bind\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-unmarshal-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-unmarshal-example\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-unmarshal-example\/\",\"name\":\"JAXB unmarshal example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-unmarshal-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-unmarshal-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"datePublished\":\"2014-06-25T11:40:33+00:00\",\"dateModified\":\"2014-07-29T12:51:31+00:00\",\"description\":\"In my last article, I've explained how to marshall java objects to xml using JAXB. In this one, we are going to see how to do the complementary operation:\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-unmarshal-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-unmarshal-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-unmarshal-example\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"Bipartite Graph\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-unmarshal-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Development\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Core Java\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"xml\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/xml\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"bind\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/xml\/bind\/\"},{\"@type\":\"ListItem\",\"position\":6,\"name\":\"JAXB unmarshal example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/ee0f431dd55475919f56a8b41e52b219\",\"name\":\"Dani Buiza\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/06\/Dani-Buiza-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/06\/Dani-Buiza-96x96.jpg\",\"caption\":\"Dani Buiza\"},\"description\":\"Daniel Gutierrez Diez holds a Master in Computer Science Engineering from the University of Oviedo (Spain) and a Post Grade as Specialist in Foreign Trade from the UNED (Spain). Daniel has been working for different clients and companies in several Java projects as programmer, designer, trainer, consultant and technical lead.\",\"sameAs\":[\"http:\/\/danibuiza.github.io\/yo\/\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/dani-buiza\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"JAXB unmarshal example - Java Code Geeks","description":"In my last article, I've explained how to marshall java objects to xml using JAXB. In this one, we are going to see how to do the complementary operation:","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-unmarshal-example\/","og_locale":"en_US","og_type":"article","og_title":"JAXB unmarshal example - Java Code Geeks","og_description":"In my last article, I've explained how to marshall java objects to xml using JAXB. In this one, we are going to see how to do the complementary operation:","og_url":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-unmarshal-example\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2014-06-25T11:40:33+00:00","article_modified_time":"2014-07-29T12:51:31+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","type":"image\/jpeg"}],"author":"Dani Buiza","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Dani Buiza","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-unmarshal-example\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-unmarshal-example\/"},"author":{"name":"Dani Buiza","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/ee0f431dd55475919f56a8b41e52b219"},"headline":"JAXB unmarshal example","datePublished":"2014-06-25T11:40:33+00:00","dateModified":"2014-07-29T12:51:31+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-unmarshal-example\/"},"wordCount":652,"commentCount":2,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-unmarshal-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","articleSection":["bind"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-unmarshal-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-unmarshal-example\/","url":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-unmarshal-example\/","name":"JAXB unmarshal example - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-unmarshal-example\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-unmarshal-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","datePublished":"2014-06-25T11:40:33+00:00","dateModified":"2014-07-29T12:51:31+00:00","description":"In my last article, I've explained how to marshall java objects to xml using JAXB. In this one, we are going to see how to do the complementary operation:","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-unmarshal-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-unmarshal-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-unmarshal-example\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","width":150,"height":150,"caption":"Bipartite Graph"},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/bind\/jaxb-unmarshal-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java Development","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/"},{"@type":"ListItem","position":3,"name":"Core Java","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/"},{"@type":"ListItem","position":4,"name":"xml","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/xml\/"},{"@type":"ListItem","position":5,"name":"bind","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/xml\/bind\/"},{"@type":"ListItem","position":6,"name":"JAXB unmarshal example"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/ee0f431dd55475919f56a8b41e52b219","name":"Dani Buiza","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/06\/Dani-Buiza-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/06\/Dani-Buiza-96x96.jpg","caption":"Dani Buiza"},"description":"Daniel Gutierrez Diez holds a Master in Computer Science Engineering from the University of Oviedo (Spain) and a Post Grade as Specialist in Foreign Trade from the UNED (Spain). Daniel has been working for different clients and companies in several Java projects as programmer, designer, trainer, consultant and technical lead.","sameAs":["http:\/\/danibuiza.github.io\/yo\/"],"url":"https:\/\/examples.javacodegeeks.com\/author\/dani-buiza\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/10815","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/21"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=10815"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/10815\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/1204"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=10815"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=10815"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=10815"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}