How to de-serialize Apache wink ClientResponse response object dynamically in lyo client project
Hi,
I have a oslc resource : https://server:port/rm/resources/_7UpQQ5zMEeWqXIur94EOpA.
I plan to perform GET on this URI in following way.
ClientResponse response = client.getResource(resultsUrl, OSLCConstants.CT_RDF);
Requirement req = response.getEntity(Requirement.class);
But my problem is that above mentioned resource URI can be of type Requirement or RequirementCollection. So how should I inspect response for rdf:type and based on its value,I should use either response.getEntity(Requirement.class) or response.getEntity(RequirementCollection.class);
I am new to APACHE WINK so kindly guide me on this issue.
Thanks in advance.
One answer
I'm new to Lyo as well, and this is what I will do for this situation.
De-serialize using the Requirement class first (this should always work). Then check the value of "instanceShape", and do a GET to find out what it is. If it turns out to be a Requirement Collection, de-serialize for the second time using the RequirementCollection class.
The reason is that the RequirementCollection class extends the Requirement class, and "uses" is the only extra field.
De-serialize using the Requirement class first (this should always work). Then check the value of "instanceShape", and do a GET to find out what it is. If it turns out to be a Requirement Collection, de-serialize for the second time using the RequirementCollection class.
The reason is that the RequirementCollection class extends the Requirement class, and "uses" is the only extra field.
Comments
Hi Nong,
Thanks
I get null object when I De-serialize RequirementCollection resource reponse as Requirement.
Am I missing something.
Regards
It seems that my assumption was wrong. I got the same result as you did when tried with a Requirement Collection. But I think you can use the null result as an indication of a Requirement Collection, right?
P.S. I have not done debugging to see why the extra "uses" properties can cause the null result.