Avoid null pointer issues in serialization