  We present a model that explains the observed deviation of the spectra of
some pulsars and magnetars from the power-law spectra which are seen in the
bulk of the pulsar population. Our model is based on the assumption that the
observed variety of pulsar spectra can be naturally explained by the thermal
free-free absorption that takes place in the surroundings of the pulsars. In
this context, the variety of the pulsar spectra can be explained according to
the shape, density and temperature of the absorbing media and the optical path
of the line-of-sight across that. We have put specific emphasis on the case of
the radio magnetar SGR J1745-2900 (also known as Sgr A* magnetar), modeling the
rapid variations of the pulsar spectrum after the outburst of Apr 2013 as due
to the free-free absorption of the radio emission in the electron material
ejected during the magnetar outburst. The ejecta expands with time and
consequently the absorption rate decreases and the shape of the spectrum
changes in such a way that the peak frequency shifts towards the lower radio
frequencies. In the hypothesis of an absorbing medium, we also discuss the
similarity between the spectral behaviour of the binary pulsar B1259-63 and the
spectral peculiarities of isolated pulsars.
