added to_object method and added test for to_array as well.