This is highly idiomatic in terms of whether it's negative or not.
In the following two, context tells you:
Congratuations! You took first place. It's nice to see that you got what you deserved after working so hard. (Positive)
So your girlfriend finally left you? The way you treated her, you got what you deserved! (Negative)
However, you deserved what you got and serves you right are both negative.
So your girlfriend finally left you? The way you treated her, you deserve what you got.