5 Replies Latest reply on Nov 8, 2006 7:56 AM by alesj

    JAXBDeserializer unmarshalling

    alesj

      I have this unmarshalling problem:

      
      @XmlRootElement(name = "createAccountReturn")
      public class Account implements Serializable {
      
       @XmlElement(name = "username") public String username;
       @XmlElement(name = "password") public String password;
       @XmlElement(name = "creationDate") public Date creationDate;
      
       public String toString() {
       return "Account{" +
       "username='" + username + '\'' +
       ", password='" + password + '\'' +
       ", creationDate=" + creationDate +
       '}';
       }
      
      }
      
       public static void main(String[] args) {
       Class javaType = Account.class;
       String xml = "<createAccountReturn xmlns='http://localhost:8080/jaxrpc/axis/AccountService'><password>password12</password><creationDate>2006-11-07T13:44:01.515Z</creationDate><username>creator</username></createAccountReturn>";
       try {
       JAXBContext jaxbContext = JAXBContext.newInstance(javaType);
       Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
       ByteArrayInputStream ins = new ByteArrayInputStream(xml.getBytes("UTF-8"));
       JAXBElement jbe = unmarshaller.unmarshal(new StreamSource(ins), javaType);
       Object value = jbe.getValue();
       System.out.println("value = " + value);
       } catch (Exception e) {
       e.printStackTrace();
       }
       }
      


      trying to unmarshall this xml:

      <createAccountReturn xmlns='http://localhost:8080/jaxrpc/axis/AccountService'>
       <password>password12</password>
       <creationDate>2006-11-07T13:44:01.515Z</creationDate>
       <username>creator</username>
      </createAccountReturn>
      


      But I always get value = Account{username='null', password='null', creationDate=null}.

      No idea what I'm doing wrong...

      Rgds, Ales