mendix / RestServices

REST service module for Mendix. Supports consuming and publishing REST based services and real-time data synchronization. Supports JSON, form-encoded, multipart and binary data transport.
Apache License 2.0
31 stars 46 forks source link

Association Issue When Consuming Webservice #73

Open mkumpf opened 8 years ago

mkumpf commented 8 years ago

I have been struggling with consuming a particular webservice for some time now and have not been able to get it working. The webservice is from Hubspot. The returned JSON is as follows:

{ "contacts":[ {"addedAt":1454958537989, "vid":1, "canonical-vid":1, "merged-vids":[], "portal-id":2016447, "is-contact":true, "profile-token":"AO_T-mOPfmNESRoTf5_p1Q546HYy-3wmBbNdfVTZT9t3838HtAHNLQy4YR91m2oO4BypNJ2s5Mou75sLW_LiS8jtm01gaS2HiVBbV_9TvK3G-HRRGx07k7wUinGlgCX_ybwFuquBGf8Y","profile-url":"https://app.hubspot.com/contacts/2016447/lists/public/contact/_AO_T-mOPfmNESRoTf5_p1Q546HYy-3wmBbNdfVTZT9t3838HtAHNLQy4YR91m2oO4BypNJ2s5Mou75sLW_LiS8jtm01gaS2HiVBbV_9TvK3G-HRRGx07k7wUinGlgCX_ybwFuquBGf8Y/", "properties":{ "firstname":{"value":"Brian"}, "lastmodifieddate":{"value":"1454959883325"}, "company":{"value":"Customer One"}, "lastname":{"value":"Humphrey"}}, "form-submissions":[], "identity-profiles":[ {"vid":1, "saved-at-timestamp":1454958536954, "deleted-changed-timestamp":0, "identities":[ {"type":"EMAIL", "value":"bh@customer1.com", "timestamp":1454958536939}, {"type":"LEAD_GUID", "value":"2abdbb41-8d96-4dfd-9060-7576ce71fff7", "timestamp":1454958536945}] }], "merge-audits":[]} ], "has-more":false, "vid-offset":1}

I have modeled this in the domain model in the following way:

image

However, after having tried several different ways, I have not been successful at getting identity-profiles to deserialize into the Mendix domain model. I am likely doing something wrong....any pointers would be appreciated.

I have tried:

tieniber commented 8 years ago

Mike,

You may have sorted this out already based on our email discussion, but if you're using the mainline REST module you need to create the identitityprofiles association as a -_ and you need to start the association line from the Contact entity.

Hope that helps! On Thu, Mar 3, 2016 at 7:00 AM mkumpf notifications@github.com wrote:

I have been struggling with consuming a particular webservice for some time now and have not been able to get it working. The webservice is from Hubspot. The returned JSON is as follows:

{ "contacts":[ {"addedAt":1454958537989, "vid":1, "canonical-vid":1, "merged-vids":[], "portal-id":2016447, "is-contact":true,

"profile-token":"AO_T-mOPfmNESRoTf5_p1Q546HYy-3wmBbNdfVTZT9t3838HtAHNLQy4YR91m2oO4BypNJ2s5Mou75sLW_LiS8jtm01gaS2HiVBbV_9TvK3G-HRRGx07k7wUinGlgCX_ybwFuquBGf8Y","profile-url":" https://app.hubspot.com/contacts/2016447/lists/public/contact/_AO_T-mOPfmNESRoTf5_p1Q546HYy-3wmBbNdfVTZT9t3838HtAHNLQy4YR91m2oO4BypNJ2s5Mou75sLW_LiS8jtm01gaS2HiVBbV_9TvK3G-HRRGx07k7wUinGlgCX_ybwFuquBGf8Y/ ", "properties":{ "firstname":{"value":"Brian"}, "lastmodifieddate":{"value":"1454959883325"}, "company":{"value":"Customer One"}, "lastname":{"value":"Humphrey"}}, "form-submissions":[], "identity-profiles":[ {"vid":1, "saved-at-timestamp":1454958536954, "deleted-changed-timestamp":0, "identities":[ {"type":"EMAIL", "value":"bh@customer1.com", "timestamp":1454958536939}, {"type":"LEAD_GUID", "value":"2abdbb41-8d96-4dfd-9060-7576ce71fff7", "timestamp":1454958536945}] }], "merge-audits":[]} ], "has-more":false, "vid-offset":1}

I have modeled this in the domain model in the following way:

[image: image] https://cloud.githubusercontent.com/assets/3680543/13496371/d127a436-e11d-11e5-9c7a-70d636e90891.png

However, after having tried several different ways, I have not been successful at getting identity-profiles to deserialize into the Mendix domain model. I am likely doing something wrong....any pointers would be appreciated.

I have tried:

  • naming the association identity_profiles and putting an attribute called identity_profiles_jsonkey in both the Contact and Identity_ProfilesItem entities
  • naming the association _identity_profiles and adding and attribute called _identity_profiles_jsonkey to both entities

— Reply to this email directly or view it on GitHub https://github.com/mendix/RestServices/issues/73.

mkumpf commented 8 years ago

Eric - thanks for the response. Based on our email discussion, I was able to get past the previous error I was having. However, I still have one question I am not sure about. In the case I mentioned here, there is an association that is named identity-profiles in the json I receive. I think I should name this association identity_profiles in my domain model. Is the correct? Also, if this were an attribute, I would then put another attribute called identity_profiles_jsonkey in the same entity with a default value of identity-profiles so the REST module can properly deserialize the attribute. However, in the case of an association, is the same thing required? And if so, which entity do I put the identity_profiles_jsonkey attribute in?

Thanks again,

Mike

On Sat, Mar 5, 2016 at 3:38 AM, tieniber notifications@github.com wrote:

Mike,

You may have sorted this out already based on our email discussion, but if you're using the mainline REST module you need to create the identitityprofiles association as a -_ and you need to start the association line from the Contact entity.

Hope that helps! On Thu, Mar 3, 2016 at 7:00 AM mkumpf notifications@github.com wrote:

I have been struggling with consuming a particular webservice for some time now and have not been able to get it working. The webservice is from Hubspot. The returned JSON is as follows:

{ "contacts":[ {"addedAt":1454958537989, "vid":1, "canonical-vid":1, "merged-vids":[], "portal-id":2016447, "is-contact":true,

"profile-token":"AO_T-mOPfmNESRoTf5_p1Q546HYy-3wmBbNdfVTZT9t3838HtAHNLQy4YR91m2oO4BypNJ2s5Mou75sLW_LiS8jtm01gaS2HiVBbV_9TvK3G-HRRGx07k7wUinGlgCX_ybwFuquBGf8Y","profile-url":"

https://app.hubspot.com/contacts/2016447/lists/public/contact/_AO_T-mOPfmNESRoTf5_p1Q546HYy-3wmBbNdfVTZT9t3838HtAHNLQy4YR91m2oO4BypNJ2s5Mou75sLW_LiS8jtm01gaS2HiVBbV_9TvK3G-HRRGx07k7wUinGlgCX_ybwFuquBGf8Y/ ", "properties":{ "firstname":{"value":"Brian"}, "lastmodifieddate":{"value":"1454959883325"}, "company":{"value":"Customer One"}, "lastname":{"value":"Humphrey"}}, "form-submissions":[], "identity-profiles":[ {"vid":1, "saved-at-timestamp":1454958536954, "deleted-changed-timestamp":0, "identities":[ {"type":"EMAIL", "value":"bh@customer1.com", "timestamp":1454958536939}, {"type":"LEAD_GUID", "value":"2abdbb41-8d96-4dfd-9060-7576ce71fff7", "timestamp":1454958536945}] }], "merge-audits":[]} ], "has-more":false, "vid-offset":1}

I have modeled this in the domain model in the following way:

[image: image] < https://cloud.githubusercontent.com/assets/3680543/13496371/d127a436-e11d-11e5-9c7a-70d636e90891.png

However, after having tried several different ways, I have not been successful at getting identity-profiles to deserialize into the Mendix domain model. I am likely doing something wrong....any pointers would be appreciated.

I have tried:

  • naming the association identity_profiles and putting an attribute called identity_profiles_jsonkey in both the Contact and Identity_ProfilesItem entities
  • naming the association _identity_profiles and adding and attribute called _identity_profiles_jsonkey to both entities

— Reply to this email directly or view it on GitHub https://github.com/mendix/RestServices/issues/73.

— Reply to this email directly or view it on GitHub https://github.com/mendix/RestServices/issues/73#issuecomment-192608280.

mweststrate commented 8 years ago

Hi @mkumpf,

Your assumption about the name identity_profiles for the association is correct. Note that the _jsonkey is only used by the RestModules for serialization, not for deserialization. But you can indeed have a _jsonkey attributes to alter the name of an association being serialized. It should be in the owning entity of the association.

Note that the complete serialization mechanism can be found here: https://github.com/mendix/RestServices/blob/master/javasource/restservices/util/JsonDeserializer.java