简体   繁体   中英

JAXB XML Unmarshalling creates xml classes's fields as well

I have an xml and and at that XML I have too many child fields such like . From the documentation that I read, I see that JAXB auto generated xml to pojo classes but there is a remark there , JAXB can create fields as well ? I meant do i have to create Employee class and its methods such like String job, String id myself or JAXB will create it themselves ? If my question is not clear, I can provide sample codes.

Cheers Alper

        <code>
           <Employee>
             <id>121</id>
             <name>Alper</name>
           </Employee>
        </code>

Do I have to create String id; String name; as well ?

You have 2 options:

  1. To create necessary Java classes (eg Employee) manually
  2. To use XML schema to generate classes

But XML sample itself is not enough surely.

More information here: https://docs.oracle.com/javase/tutorial/jaxb/intro/examples.html

you can generate POJO or java class from JAXB in eclipse, command line or maven.

you can file below several tutorials to learn this:

create POJO Class from XSD in Eclipse here

create POJO class from XSD using command line here

create POJO Class from XSD using XJC Maven Plugin here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM