Checking that the connection is not null in JsonSerializeObject