Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Use JAXB implementation. </p> <p>some of the references are:</p> <p>1><a href="http://javapapers.com/jee/jaxb-tutorial/" rel="nofollow">code geekers</a></p> <p>2><a href="http://www.techferry.com/articles/jaxb-annotations.html" rel="nofollow">techferry</a></p> <p>3><a href="http://www.vogella.com/articles/JAXB/" rel="nofollow">vogella</a></p> <p>4><a href="http://javapapers.com/jee/jaxb-tutorial/" rel="nofollow">java papers</a></p> <pre><code>String USER_DETAILS_XML = "./user-details.xml"; String USER_ERROR_XML = "./user-error.xml"; public String login(String username, String password) throws JAXBException, PropertyException, FileNotFoundException { User user = new User(); InvalidUser invalidUser = new InvalidUser(); if ((username !=null &amp;&amp; password !=null)) { user.setUserName(username); user.setFirstName("Jose"); user.setLastName("Tom"); JAXBContext jaxbContext = JAXBContext.newInstance(User.class); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.marshal(user, System.out); marshaller.marshal(user,new File(USER_DETAILS_XML)); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); User userResult = (User) jaxbUnmarshaller.unmarshal(new FileReader( USER_DETAILS_XML)); return userResult.getFirstName(); } else{ invalidUser.setCode(400); invalidUser.setMessage("something wrong here"); JAXBContext jaxbContext = JAXBContext.newInstance(InvalidUser.class); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.marshal(invalidUser, System.out); marshaller.marshal(invalidUser, new File(USER_ERROR_XML)); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); InvalidUser invalidUserResult = (InvalidUser) jaxbUnmarshaller.unmarshal(new FileReader(USER_ERROR_XML)); return invalidUserResult.getMessage(); } } </code></pre> <p>User.java:</p> <pre><code>@XmlRootElement(name = "user") @XmlType(propOrder = { "userName", "firstName", "lastName" }) public class User{ private String userName; private String firstName; private String lastName; ....get/set </code></pre> <p>}</p> <p>InvalidUser.java:</p> <pre><code>@XmlRootElement(name = "status") @XmlType(propOrder = { "code", "message" }) public class InvalidUser { private int code; private String message; ...set/get } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload