v.22.4Bug Fix

Fix bug in custom types to string conversion causing segfaults

Fix bug in conversion from custom types to string that could lead to segfault or unexpected error messages. Closes #35752. #35755 (Kruglov Pavel).