I have a Java Jersey client that works fine unmarshalling XML to a POJO from passed data from a Jersey web service, but the same equivalent Groovy script gets Parsing and NullPointer exceptions. Has anyone run into this? Is there something extra I need to do to get this to work with Groovy?
We use Groovy for Spock testing. I have also run into the same issue marshalling XML data when I call a POST service with Groovy.
Here's the server code:
@GET
@Produces(MediaType.APPLICATION_XML)
public JAXBElement<WidgetType> getWidget() {
return new JAXBElement<WidgetType>(new QName("widget"), WidgetType.class, widget);
}
Here's the Java client which works fine:
// Create widget from XSD generated class "WidgetType"
WidgetType widget = new WidgetType();
// Get - Fetch data from server "query"
// Unmarshall Generic XML data to type
GenericType<JAXBElement<WidgetType>> genericXMLWidgetType = new GenericType<JAXBElement<WidgetType>>() {};
widget = (WidgetType) widgetService.request(MediaType.APPLICATION_XML_TYPE).get(genericXMLWidgetType).getValue();
Here's the Groovy code that gets a ProcessingException and NullPointerException apparently while unmarshalling the XML data:
// Create widget from XSD generated class "WidgetType"
WidgetType widget = new WidgetType()
// Get - Fetch data from server "query"
// Unmarshall Generic XML data to type
GenericType<JAXBElement<WidgetType>> genericXMLWidgetType = new GenericType<JAXBElement<WidgetType>>() {}
widget = (WidgetType) widgetService.request(MediaType.APPLICATION_XML_TYPE).get(genericXMLWidgetType).getValue()
Here's the RAW XML Data sent back:
<?xml version="1.0" encoding="UTF-8" standalone="true"?>
<widget>
<WidgetId>1</WidgetId>
</widget>
No comments:
Post a Comment