add marshalJson for metadata, and extract the logic to set metadata without registering.