Now when I post this I guess the first thing to do is deserialize this back to a TPerson. However, the deserializer gives an exception: No duplicates allowed. I think this is because some internal meganism relies on the $id value and that is indeed duplicate now.
So my question:
With a Datasnap rest-client and the above example, what is the suggested method to change, in a javascript REST-client, the country for this person?
I hope you can help me out, I am realy looking forward to use aurelius and buy a copy once I get this to work!
Hello, this should work. The id of TCountry should not be in conflict with the id of TPerson, Can you post more parts of the code, how you change the country, how do you deserialize, so that we can have a better idea?
Create a new Datasnap REST server with the wizard, include the sample methods (reversestring, echostring). Replace ServerMethodsUnit1 with the code below.
Notice that both TPerson and TCountry have $id = 1. Change one of them to $id = 2 and EXECUTE -> No problem, verify the change by executing Person again.
So I guess it has something to do with the duplicate $id?
Ah, ok. Yes, the $id is just an internal name for the json serializer/deserializer. It MUST be unique among all objects in a single JSON representation.
But how can I make a change to a JSON object then? Right now the JSON serialization is sort of 'read-only' since it is not possible to substitue one sub-object for another if they have the same $id. The person-country relation kind of relation is very common in business applications.
I believe you are replacing the json string directly? If yes, that's the problem. If you just use the json serializer, it will automatically set the id values for you
I dont'understand your answer. I have a Javascript client that receives the json from the serializer.
First GET-request: the list of countries.
Second GET-request: the person (incl the country that belongs to this person).
The person json is changed (the country is substituted) and then posted back to Datasnap where it is passed to the deserializer, which fails.
Can you show an example or explain to me how this can or should be be implemented? What I want (I'll just relate it to this example): have a webpage where a person is loaded, the person.country is changed and then the person is saved.