/** * @param $toSerialize * @param $encodingType * @return string */ public function serialize($toSerialize, $encodingType) { if (is_null($this->getSerializer())) { $this->setSerializer($this->serializerFactory->create()); } return $this->getSerializer()->serialize($toSerialize, $encodingType); }
/** * @return \Symfony\Component\Serializer\Serializer */ protected function getSerializer() { $ignore = ['id', 'salt', 'password', 'plainPassword', 'lastLogin', 'confirmationToken', 'accountNonExpired', 'accountNonLocked', 'credentialsNonExpired', 'credentialsExpired', 'expired', 'locked', 'passwordRequestedAt', 'groups', 'groupNames', 'emailCanonical', 'usernameCanonical', 'enabled', 'superAdmin']; $this->serializerFactory->setIgnoredAttributes($ignore); $normalizers = [new GetSetMethodNormalizer(), new ObjectNormalizer()]; $this->serializerFactory->setNormalizers($normalizers); $serializer = $this->serializerFactory->create(); return $serializer; }