RoyZeng / odata4j

Automatically exported from code.google.com/p/odata4j
0 stars 0 forks source link

Exception while trying to send an entity set to change a one-to-many navigation property in JSON #155

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Try to merge an entity with a one-to-many navigation property in JSON, 
sending a representation of the entity set according to spec.

What is the expected output? What do you see instead?
Change the entity set. odata4j throws and exepction.

What version of the product are you using? On what operating system?
0.6

According to spec in
http://msdn.microsoft.com/en-us/library/dd541389(v=prot.10).aspx
and
http://msdn.microsoft.com/en-us/library/dd541221(v=prot.10).aspx
I think the following request should be valid (where User.devices is a 
one-to-many navigation property):

Headers:

POST /datastore.svc/User(180L) HTTP/1.1
Host: 127.0.0.1:8888
Content-Length: 213
Origin: http://127.0.0.1:8888
X-HTTP-Method: MERGE
Content-Type: application/json
Accept: application/json

Payload:
{"devices":[{"__metadata":{"uri":"http://127.0.0.1:8888/datastore.svc/Device(126
L)","type":"Datastore.Device"}},{"__metadata":{"uri":"http://127.0.0.1:8888/data
store.svc/Device(137L)","type":"Datastore.Device"}}]}

odata4j exception:
WARNING: /datastore.svc/User(180L)
java.lang.IllegalArgumentException: no valid OData JSON format (expected 
StartProperty got EndObject('}'))
    at org.odata4j.format.json.JsonFormatParser.ensureStartProperty(JsonFormatParser.java:426)
    at org.odata4j.format.json.JsonFormatParser.addProperty(JsonFormatParser.java:208)
    at org.odata4j.format.json.JsonFormatParser.parseEntry(JsonFormatParser.java:143)
    at org.odata4j.format.json.JsonFormatParser.addProperty(JsonFormatParser.java:272)
    at org.odata4j.format.json.JsonFormatParser.parseEntry(JsonFormatParser.java:143)
    at org.odata4j.format.json.JsonEntryFormatParser.parse(JsonEntryFormatParser.java:47)
    at org.odata4j.format.json.JsonEntryFormatParser.parse(JsonEntryFormatParser.java:11)
    at org.odata4j.producer.resources.BaseResource.convertFromString(BaseResource.java:35)
    at org.odata4j.producer.resources.BaseResource.getRequestEntity(BaseResource.java:29)
    at org.odata4j.producer.resources.EntityRequestResource.mergeEntity(EntityRequestResource.java:66)
(...)

Original issue reported on code.google.com by miguel.ans@gmail.com on 29 Mar 2012 at 4:42

GoogleCodeExporter commented 8 years ago
Trying to update a navigation property and sending only one entity, works 
(where Location.owner is a one-to-one navigation property):

Headers:

POST /datastore.svc/Location(222L) HTTP/1.1
Host: 127.0.0.1:8888
Connection: keep-alive
Content-Length: 105
X-HTTP-Method: MERGE
Content-Type: application/json
Accept: application/json

Payload:

{"owner":{"__metadata":{"uri":"http://127.0.0.1:8888/datastore.svc/User(183L)","
type":"Datastore.User"}}}

Original comment by miguel.ans@gmail.com on 29 Mar 2012 at 4:45

GoogleCodeExporter commented 8 years ago
Problem still exists in 0.7.0.
Any update on this issue?

Original comment by miguel.ans@gmail.com on 22 Nov 2012 at 10:17

GoogleCodeExporter commented 8 years ago
After looking into the json stream parser it looks like to me that odata4j 
tries to parse the __metadata as a normal name:string property, and of course 
it fails. The exact same exception happens even on merge requests not having 
any associations (without the __metadata part they are all successful). The 
problem still persists in 8.0-SNAPSHOT.

Original comment by borsos.a...@gmail.com on 31 Oct 2014 at 3:03

GoogleCodeExporter commented 8 years ago
Any Update on how this can be achieved? I need an alternative way for this

Original comment by sudheerm...@gmail.com on 14 Jun 2015 at 5:36