Are you trying to create an User object and serialize it using the above code? It won't work this way, because what you are actually creating in the above statement is a String object. So you will get a ClassCastException when you try to cast it into an User object. Try the following code