Linking
Now that Version 2 of the contact service supports two data formats: JSON for storing contacts and binary format for storing an image file associated with a contact, we need to ensure that these data formats are not mixed. In the previous section, Working with arbitrary data, the information stored for a contact was extended with an additional file entry in MongoDB that stored the binary representation of a JPEG image.
However, none of the JSON models in previously exposed routes, /v2/contacts
or /v2/contacts/{primary-number}
, adopted that change, and the image was exposed in a new route:/v2/contacts/{primary-number|}/image
. That was done intentionally, and keeping backward compatibility was not the main reason for that decision. Mixing literally encoded and binary data in one format is never a good idea. It increases the complexity of the application and makes it error-prone. Thus, we would want to prevent a JSON representation of a contact from looking like this:
{ "firstname...