0

Calling a Rest Webservice using the Spring Rest Template as follows-

ResponseEntity<String> response = restTemplate.exchange(builder.build().encode().toUri(), HttpMethod.GET, entity, String.class); 

and get the output in String format as

<Info xmlns="http://schemas.test.org/2009/09/Tests.new" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<FirstName>FirstName</FirstName>
<LastName>LastName</LastName>
<TestGuid>Guid</TestGuid>
<TestUID>1</TestUID>
<Token>token</Token>
<TestUserID>14</TestUserID>
</Info>

When trying to unmarshal it to java class as follows

ResponseEntity<Info> response = restTemplate.exchange(builder.build().encode().toUri(), HttpMethod.GET, entity, Info.class)

The Info class is defined as

@XmlRootElement(name = "Info", namespace = "http://schemas.test.org/2009/09/Tests.new")
public class Info implements Serializable{

    private String firstName;
    private String lastName;
    private String testGuid;
    private String testUID;
    private String token;
    private String testUserID;

    //getters and setter

}   

get all values of the info class null like Firstname=null..

Could anyone tell what is missing? Thanks

Rehan
  • 929
  • 1
  • 12
  • 29

1 Answers1

0

You need to map you java class like this

@XmlRootElement(name = "Info", namespace = "http://schemas.test.org/2009/09/Tests.new")
@XmlAccessorType(XmlAccessType.FIELD)
public class Info implements Serializable{

    @XmlElement(name="FirstName")
    private String firstName;
    @XmlElement(name="LastName")
    private String lastName;
    @XmlElement(name="TestGuid")
    private String testGuid;
    @XmlElement(name="TestUID")
    private String testUID;
    @XmlElement(name="Token")
    private String token;
    @XmlElement(name="TestUserID")
    private String testUserID;

    //getters and setter

}   
codependent
  • 23,193
  • 31
  • 166
  • 308