Necessary and sufficient conditions for the validity of Jensen’s inequality