Saturday, December 1, 2012

Forward compatible data consumption

Forward compatibility means ignoring new fields should they arise ... passing them through if possible, ignoring them if they can't be passed through.  i.e. FOCUS ONLY ON WHAT YOU ALREADY KNOW and ignore the rest.

This means in XML parsing, if you are using annotation based parsing - tell it to ignore fields and objects it doesn't understand and continue with the rest, or if manually parsing to only concentrate on known objects and ignore the rest.

Same thing for json, annotations (like Jackson) need to be told to ignore fields that can't be mapped into the objects in a known way and to proceed with everything it does understand.

This way other systems can include new information that could be consumed at some later date without impact to the system at hand.

Why is all the above at all relevant or important - these steps are vitally important to the compatibility of APIs that you might be developing. In order for the API to be forward and backward compatible as changes to it are made the API system must be able to accept new things or ignore things it does not currently understand. APIs have to hold themselves accountable for what they 'know' they can do - and things that can safely be ignored.  If the API you are developing can't ignore things it doesn't understand, then errors get returned to the clients that may have otherwise resulted in a useable response from the API.
Post a Comment