Skip to main content

JSON/JAXB POST request problem

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
No replies
thepopeofantelope
Offline
Joined: 2011-08-12

I have exposed a REST @POST method annotated to produce and consume XML and JSON. The method parameter and response class is a JAXB object. When called with wget and an XML request the correct XML responsed is returned. When I make a wget XML request and ask for a JSON response using the 'accept' http header I get the correct JSON response returned. My problem is when I use wget to make a JSON request I get an incorrect response. The JSON request is not being mapped to the method JAXB object parameter.

I am using Glassfish 3.0.1 and Netbeans 6.9.1 to generate and publish my war. I enabled logging using the LoggingFilter and can see my JSON request properly being recieved:

[#|2011-08-11T17:15:12.171-0700|INFO|glassfish3.0.1|com.sun.jersey.api.container.filter.LoggingFilter|_ThreadID=25;_ThreadName=Thread-1;|3 * Server in-bound request
3 > user-agent: Wget/1.12 (linux-gnu)
3 > accept: application/json
3 > host: localhost:38080
3 > connection: Keep-Alive
3 > content-type: application/json
3 > content-length: 242
3 >
{"inventorydata": {
"messageheader":{
"timedate":"2011-08-09T21:12:10.092Z",
"client":"10395",
"guid":"7cb18cc0-f945-47c6-9a8f-789bbc345a51"
}
}
}
I have added a custom JAXB Context Resolver(using natural builder) and see my logger messages when it is called with each JSON or XML request. My method is called with an empty JAXB object. The object when marshalled prints an empty XML payload:
[#|2011-08-11T17:16:40.887-0700|INFO|glassfish3.0.1|javax.enterprise.system.std.com.sun.enterprise.v3.services.impl|_ThreadID=24;_ThreadName=Thread-1;|<?xml version="1.0" encoding="UTF-8" standalone="yes"?><inventoryData xmlns="http://www.ragingwire.com/soa/2010-04-22/InventoryData.xsd"/>|#]
I haven't been able to find a reference example or tutorial that demonstrates this configuration.