I have observered an strange behaviour on JSON deserialize
As per documentation deserialize(jsonString, apexType)
If the JSON content contains attributes not present in the System.Type argument, such as a missing field or object, deserialization fails in some circumstances. When deserializing JSON content into a custom object or an sObject using Salesforce API version 34.0 or earlier, this method throws a runtime exception when passed extraneous attributes. When deserializing JSON content into an Apex class in any API version, or into an object in API version 35.0 or later, no exception is thrown. When no exception is thrown, this method ignores extraneous attributes and parses the rest of the JSON content.
According above statement, when we deserialize json, any extra field should get ignored.
Below i have include some inValidfield in json and it get parsed without an error. Above statement holds true for parent record,
String jsonString='{"inValidField":"Burlington","Name":"Burlington","Contacts":{"totalSize":1,"done":true,"records":[{"Name":"Jack Rogers"}]}}';
Account acc = (Account) JSON.deserialize(jsonString, Account.class);
where as when i include inValidfield field on child record, it start give me an error
System.JSONException: No such column 'inValidField' on sobject of type Contact
String jsonString='{"inValidField":"Burlington","Name":"Burlington","Contacts":{"totalSize":1,"done":true,"records":[{"inValidField":"Burlington","Name":"Jack Rogers"}]}}';
Account acc = (Account) JSON.deserialize(jsonString, Account.class);
Anyone know how to resolve such issue of parsing ?