It's all about the answers!

Ask a question

How to de-serialize Apache wink ClientResponse response object dynamically in lyo client project


Amit Kumar (38419) | asked Mar 01 '16, 10:01 p.m.
 
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



permanent link
Donald Nong (14.5k614) | answered Mar 02 '16, 12:10 a.m.
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.

Comments
Amit Kumar commented Mar 02 '16, 12:52 a.m.

 Hi Nong,

Thanks

I get null object when I De-serialize RequirementCollection resource reponse as Requirement.

Am I missing something.

Regards




Donald Nong commented Mar 02 '16, 3:09 a.m.

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.

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.