refactored custom string serialization for be complaint to utf8. issue #2636