This code is moved out from what we had in the Django python deserializer.