Json::encode did not handle JsonSerializable objects

it checks for ArrayAble and calls toArray() but that should not be done if JsonSerializable is implemented.