Hi,
I cannot reproduce this for 1.0 or 1.0.1-SNAPSHOT using the embedded
Grizzly server on the Mac.
What version of Jersey are you using?
I modified the HelloWorld sample to be:
@Path("/helloworld")
public class HelloWorldResource {
@GET
@Produces({"application/json", "application/xml"})
public JAXBBean getClichedMessage() {
return new JAXBBean("content");
}
@POST
@Produces({"application/json", "application/xml"})
@Consumes({"application/json", "application/xml"})
public JAXBBean postComment(JAXBBean comment) {
return comment;
}
with the JAXBBean:
@XmlRootElement
public class JAXBBean {
public String value;
public JAXBBean() {}
public JAXBBean(String str) {
value = str;
}
public boolean equals(Object o) {
if (!(o instanceof JAXBBean))
return false;
return ((JAXBBean) o).value.equals(value);
}
public String toString() {
return "JAXBClass: "+value;
}
}
With the following dependency added to the pom:
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>${project.version}</version>
</dependency>
And the following curl commands work correctly:
curl -v --data-binary '{"value":"content"}' -H"Content-Type:
application/json" -H"Accept: application/xml" \
http://localhost:9998/helloworld
curl -v --data-binary '{"value":"content"}' -H"Content-Type:
application/json" -H"Accept: application/json" \
http://localhost:9998/helloworld
The following results in an error:
curl -v --data-binary '{"value":"content"}' -H"Content-Type:
application/xml" -H"Accept: application/json" \
http://localhost:9998/helloworld
I doubt it is a Jetty issue. The obvious errors might be:
1) The Content-Type is not set to application/json; or
2) the jersey-json jar is not included in the class path (if using the
jersey-bundle.jar then json functionality is included).
Paul.
On Nov 29, 2008, at 10:29 AM, sarat.pediredla wrote:
>
> Hi Naresh,
>
> I don't think this is the same issue. Sorry if I missed mentioning
> this but
> I am running on Mac OSX Leopard in Jetty 6. Also, the call is not
> being made
> from a WebResource client but actually from the browser (Firefox 3).
> I tried
> the same POST using cURL at the command line but I get the same
> problems.
>
> Does this mean the problem lies with Jetty? Is there a work-around I
> can
> implement? One thing I am confused about is that the JSON POST seems
> to
> invoke a SAXParser, which I thought was for XML. I also know that the
> "Content is NOT allowed in Prolog" is only an issue with XML content.
>
> I implemented a custom @Provider and logged the MediaType being
> passed in
> the POST and it correctly says application/json, so I wonder why
> Jersey
> thinks the content is XML?
>
>
> Srinivas Naresh Bhimisetty wrote:
>>
>> Hi Sarat,
>>
>> are you trying this using the HTTPServer for deployments, and in
>> the
>> Windows environment?
>> I have observed the same behavior on Windows while using
>> "application/json", it however works fine in other environments like
>> Linux or Solaris.
>> This appears to be a bug with the light-weight HTTP Server on
>> Windows.
>> Please check the attached mail thread for more details.
>>
>> Thanks,
>> Naresh
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>
> --
> View this message in context: http://n2.nabble.com/Posting-JSON-with-Content-Type-application-json-%28jQuery%29-tp1590347p1591905.html
> Sent from the Jersey mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>