* Do JSON serialization only if requested by mime-type (#13456) * Refactoring based on feedback to PR (#13456)