Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force case sensitive JSON for dynamic model deserialization #83

Open
4 tasks done
maniax89 opened this issue Mar 6, 2018 · 1 comment
Open
4 tasks done

Force case sensitive JSON for dynamic model deserialization #83

maniax89 opened this issue Mar 6, 2018 · 1 comment
Labels

Comments

@maniax89
Copy link
Contributor

maniax89 commented Mar 6, 2018

JSON deserialization for models using IBMWatsonDynamicModel fails when JSON object keys are case insensitive.

The following Apex code can be run and errors out with: System.JSONException: Duplicate field: IBMDiscoveryV1Models.QueryResult.id_serialized_name

String responseText = '{"id":"1","Id":"2"}';
Map<String, Object> jsonMap = (Map<String, Object>) JSON.deserializeUntyped(responseText);
Map<String, Object> safeJsonMap = IBMWatsonJSONUtil.prepareResponse(jsonMap);
String jsonString = JSON.serialize(safeJsonMap);
IBMDiscoveryV1Models.QueryResult foo = (IBMDiscoveryV1Models.QueryResult) new IBMWatsonDynamicModel().deserialize(jsonString, safeJsonMap, IBMDiscoveryV1Models.QueryResult.class);
System.debug(foo);

I would expect that the Id field would get deserialized into the additional_properties and id would be deserialized to just id_serialized_name. The alternative is to not try and mix dynamic and static model types and just make the entire object dynamic (everything is a Map<String, Object>)

When reporting a bug, please be sure to include the following

  • SDK version - 1.0
  • Steps to reproduce
  • Expected behavior
  • Actual behavior
@lpatino10
Copy link
Contributor

I took a quick look at this to try and get a fix in for the upcoming release but don't see a quick solution at the moment. The section where the code fails is after calling the built-in JSON.deserialize() method, so I think fixing this would take writing some custom deserialization logic similar to how we've done in other places.

I'll leave this issue open for now as a reminder to maybe look at it in the future (and because I do agree it's a problem), but right now it's just a big limitation of the language that I'm not going to prioritize.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants