Fix json generation bug

If a message consists entirely of optional fields and none of them are set then the message gets serialized to Json as `{` instead of `{}`.