public String serialize(FieldSet fieldSet) {
        if (fieldSet instanceof Field) {
            return ((Field)fieldSet).getName();
        } else if (fieldSet instanceof FieldCollection) {
            FieldCollection c = ((FieldCollection)fieldSet);

            StringBuilder buffer = new StringBuilder();
            for (Field f : c) {
                if (buffer.length() == 0) {
                    buffer.append(c.getDocumentType().getName());
                    buffer.append(":");
                } else {
                    buffer.append(",");
                }
                buffer.append(f.getName());
            }

            return buffer.toString();
        } else if (fieldSet instanceof AllFields) {
            return AllFields.NAME;
        } else if (fieldSet instanceof NoFields) {
            return NoFields.NAME;
        } else if (fieldSet instanceof DocIdOnly) {
            return DocIdOnly.NAME;
        } else if (fieldSet instanceof DocumentOnly) {
            return DocumentOnly.NAME;
        } else {
            throw new IllegalArgumentException("Unknown field set type " + fieldSet);
        }
    }
TODO: Move to document and implement
document/src/main/java/com/yahoo/document/fieldset/FieldSetRepo.java