Let $f(\cdot)$ be a convex function and let $g(\cdot)$ be any function. According to Jensen's inequality, we know $$f[E(X)]\leq E[f(X)].$$
However, is the following true or not? $$f[E(g(X))]\leq E[f(g(X))].$$
Note we are taking expectation with respect to $g(X)$, instead of moving the expectation into the argument of $g(\cdot)$.
I will assume that $X: \Omega \rightarrow \mathbb{R}^d$ for some $d$ and some probability space $\Omega$, and that $f,g:\mathbb{R}\rightarrow \mathbb{R}$. A further, key assumption is that $g$ is measurable. Note that a sufficient condition for measurability of $g$ is piecewise continuity (with finitely many junmps).
Then $Y\:=g(X):\Omega \rightarrow \mathbb{R}$ is still a random variable, as random variables are measurable functions and composition of measurable functions is measurable, and thus you can apply Jensen inequality to $Y$, yielding $f[E(g(X))]\leq E[f(g(X))]$.
If $g$ is non-measurable, you might not be able to say that $Y$ is a random variable, and defining its expected value in the first place.