Search code examples
jaxbunmarshallingstringreader

Creating null object for input StringReader using JAXBContext


I am trying to create bean from string but unable to create as it is returning null.Here is my code

public ModelAndView checkPhotoQualityRequest(
        @RequestBody String photoDataXml, HttpServletRequest request) {
    PhotoQuality photoQuality = null;
    try {
JAXBContext jaxbContext = JAXBContext
                .newInstance(PhotoQuality.class);
        Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
        StringReader reader = new StringReader(photoDataXml);
        photoQuality = (PhotoQuality) unmarshaller.unmarshal(reader);

PhotoQuality.java

package in.gov.uid.opencvaccess.bean;

import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

@XmlType(name = "PhotoQuality")
@XmlRootElement(name = "PhotoQuality")
public class PhotoQuality {


private String photoid;
private byte[] photo;
private boolean quality;
private String message;
public String getMessage() {
    return message;
}
public void setMessage(String message) {
    this.message = message;
}
public String getPhotoid() {
    return photoid;
}
public void setPhotoid(String photoid) {
    this.photoid = photoid;
}
public byte[] getPhoto() {
    return photo;
}
public void setPhoto(byte[] photo) {
    this.photo = photo;
}
public boolean isQuality() {
    return quality;
}
public void setQuality(boolean quality) {
    this.quality = quality;
}

}

Please help me to sort out this issue.When I debug and check bean its showing all null values but photoDataXml showing complete xml.


Solution

  • I have found the reason.When I tried using RESTClient its giving null object. But as soon as I written client code and passed StringWriter value created from PhotoQuality Object then it runs properly.