class DefaultStringEntityReferenceSerializer implements EntityReferenceSerializer<String> {

    public String serialize(EntityReference reference)
    {
        if (reference == null) {
            return null;
        }

        EntityReference currentReference = reference.getRoot();
        StringBuilder representation = new StringBuilder();
        // While we still have children and they're not the children of the reference to serialize 
        while (currentReference != null && currentReference != reference.getChild()) {
            serializeEntityReference(currentReference, representation, currentReference == reference);
            currentReference = currentReference.getChild();
        }
        return representation.toString();
    }

}