You can try by creating an object of objectManager and should not use objectManager directly.
Use something like,
class Example extends \Magento\Framework\View\Element\Template
{
private $_objectManager;
public function __construct(
\Magento\Framework\ObjectManagerInterface $objectmanager
){
$this->_objectManager = $objectmanager;
}
public function getExample()
{
$customerSession = $this->_objectManager->create("Magento\Customer\Model\Session");
if ($customerSession->isLoggedIn()) {
$customerData = $customerSession->getCustomer()->getData();
/*Your logic*/
}
}
}