Fix integer handling when encoding configuration

This PR fixes #1812.  Includes API tests and integration tests for the regression.
Shouldn't the key also be encoded?