Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

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.

0 votes



One answer

Permanent link
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.

0 votes

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.

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 11,078

Question asked: Mar 01 '16, 10:01 p.m.

Question was seen: 5,014 times

Last updated: Mar 02 '16, 3:09 a.m.

Confirmation Cancel Confirm