Backport string field encode fixes from 2.8.x branch
Merge pull request #122 from localshred/bj/backport_string_field_issues

Backport string field encode fixes from 2.8.x