[jboss-user] [JBossWS] - JAXBDeserializer unmarshalling

alesj do-not-reply at jboss.com
Tue Nov 7 09:25:15 EST 2006


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

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3983764#3983764

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3983764



More information about the jboss-user mailing list