Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

problem converting xml into bean using betwixt

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,i need to parse a xml,which contains a list(UserPermissions) and an object(Users) into an object called "UserResponse". after parsing iam able to get that object(Users),but,iam unable to get the list(UserPermissions),instead i am getting the "NullPointerException".i am posting the xml:
<SelectUsersResponse>
<storeObjects>
<UserPermissions>
<permissionName>naresh</permissionName>
<permissionValue>abc</permissionValue>
<userName>naresh</userName>
</UserPermissions>
<UserPermissions>
<permissionName>screen1</permissionName>
<permissionValue>true</permissionValue>
<userName>naresh</userName>
</UserPermissions>
</storeObjects>
<users>
<password>naresh</password>
<userName>naresh</userName>
</users>
</SelectUsersResponse>

and the class "SelectUserResponse":
public class SelectUsersResponse {
public SelectUsersResponse(){}


private List storeLists;
private Users users;

public Users getUsers() {
return users;
}

public void setUsers(Users users) {
this.users = users;
}

public List getStoreObjects() {
return storeLists;
}

public void setStoreObjects(List storeObjects) {
this.storeLists = storeObjects;
}

}


and the registration of these classes at custom path:
public static Object xmlToBean(byte[] theXml) throws IntrospectionException, IOException, SAXException {


BeanReader beanReader = new BeanReader();
beanReader.registerBeanClass( "users",Users.class);
beanReader.registerBeanClass("userPermissions",UserPermissions.class);
beanReader.registerBeanClass("SelectUserPermissionsRequest", SelectUserPermissionsRequest.class);
beanReader.registerBeanClass("SelectUsersResponse",SelectUsersResponse.class );
beanReader.registerBeanClass("storeObjects",List.class );

System.out.println("the xml ready to be parsed is"+new String(theXml));
Object o = beanReader.parse(new ByteArrayInputStream(theXml));
return o;
}
please help me out. i tried my level best to frame the question.thanks in advance
 
author
Posts: 3281
8
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there and welcome to Javaranch, a couple of admin things first.

1.) Please do adhere to the Javaranch naming policy e.g. Your display name needs to be a 'real' first and last name.

2.) Please do use when listing your sample code.

Now onto your question .

As far as I can see you have the UserPermissions tag appearing in your XML on more than one occasion, yet you are trying to bind it to a single object, are you sure you shouldn't be binding it to a list as well?
 
I've never won anything before. Not even a tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic