Skip to content

Force case sensitive JSON for dynamic model deserialization #83

@maniax89

Description

@maniax89

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions