Unmarshal references according to the metadata type

Change-Id: I540b7fd75da7c551ed4999e78af192027819a774