|
|
Re: JPA-RS problem: java.lang.ClassCastException: java.util.ArrayList cannot be cast... [message #1007537 is a reply to message #1007360] |
Wed, 06 February 2013 05:57   |
Eclipse User |
|
|
|
Now I am using EclipseLink 3.4.2, and tried it with the following simple entity class without relationships:
@Entity
@NamedQueries({
@NamedQuery(name="Test.findAll",
query="SELECT t FROM Test t")
})
public class Test implements Serializable {
@Id
@GeneratedValue
private long id;
@Column
private String userId;
@Column
private List<String> names;
}
The ClassCastException occurs when I define the object wrapped inside [] brackets. I have tried to use the PUT method with the following request bodies:
{
"id": 1,
"userId": "TEST",
"names": ["one","two"]
}
The previous is executed successfully. I would expect that I don't have to specify the id field, since it is a @GeneratedValue, however for this request body:
{
"userId": "TEST",
"names": ["one","two"]
}
i get this response:
Quote:400 - Bad Request The request sent by the client was syntactically incorrect (Bad Request).
What am I doing wrong? Is this the normal behavior?
[Updated on: Wed, 06 February 2013 11:21] by Moderator
|
|
|
|
|
|
|
Re: JPA-RS problem: java.lang.ClassCastException: java.util.ArrayList cannot be cast... [message #1012854 is a reply to message #1011925] |
Fri, 22 February 2013 05:37   |
Eclipse User |
|
|
|
Thanks for your response! I updated EclipseLink to 'eclipselink-2.5.0.v20130220-795a5ad' (nightly). Now, both POST and PUT result in this error message:
Quote:
HTTP Status 415 - Unsupported Media Type
The server refused this request because the request entity is in a format not supported by the requested resource for the requested method (Unsupported Media Type).
is set in header.
UPDATE
Okay, I changed the header to Content-Type: application/json and now it seems to work.
Now I would expect that I should use POST to insert an entity and use PUT to update an entity. Is that right? At the moment I can do both with POST, but PUT throws an internal server error (HTTP code 500):
Quote:
org.eclipse.persistence.exceptions.TransactionException
Exception Description: Error committing externally managed transaction
Where the request body is:
{
"id": 1,
"userId":"test",
"names":["one","two","three"]
}
Are there examples/tutorials out there which explain how to convert the retrieved data back to object instances? I tried to do so with Jackson, but it cannot consume the "_relationships" attribute.
[Updated on: Wed, 27 February 2013 10:58] by Moderator
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05419 seconds