Is there an entire non-linear function $f$ such that, for all $x\in\mathbb{R}$, $x$ is rational if and only if $f(x)$ is?

More generally, if $A,B\subseteq \mathbb{R}$ are two countable dense sets then is there an entire function such that $f(A)=B$?