Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8429349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:18:41+00:00 2026-06-10T05:18:41+00:00

I have a problem while json_encodeing a Entity. public function jsonvoteAction($id) { $em =

  • 0

I have a problem while json_encodeing a Entity.

public function jsonvoteAction($id) {
    $em = $this->getDoctrine()->getEntityManager();
    $entity = $em->getRepository('KorumAGBundle:AGVote')->findOneById($id);
    $response = new Response(json_encode($entity, 200));
    $response->headers->set('Content-Type',' application/json');
    return $response;
    }

This code returns me a the users entity

 {"users":{"__isInitialized__":false,"id":null,"nickname":null,"pwd":null,"email":null,"firstname":null,"lastname":null,"poste":null,"addr1":null,"addr2":null,"pc":null,"country":null,"phone":null,"province":null,"acess":null,"site":null,"crew":null,"utilisateur":null}}

And when I var dymp my $entity, it returns both my AGVote and USers entity.

Here is my AGVote Entity

    <?php
    namespace Korum\AGBundle\Entity;

    use Doctrine\ORM\Mapping as ORM;

    /**
     * Korum\AGBundle\Entity\AGVote
     * @ORM\Entity
     * @ORM\HasLifecycleCallbacks
     */
    class AGVote
    {
        /**
         * @ORM\Id
         * @ORM\Column(type="integer")
         * @ORM\GeneratedValue(strategy="AUTO")
         * 
         */
        private $id;

         /**
         * @ORM\Column(type="text")
         */
        private $question;

        /**
         * @ORM\Column(type="smallint")
         */
        private $actif;

         /**
         * @ORM\ManyToOne(targetEntity="\Korum\KBundle\Entity\Users", cascade={"all"})
         */
        public $users;

   /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set question
     * Nb : Only AG admin can set a question
     * @param text $question
     */
    public function setQuestion($question)
    {
        $this->question = $question;
    }

    /**
     * Get question
     *
     * @return text 
     */
    public function getquestion()
    {
        return $this->question;
    }

    /**
     * Set actif
     *
     * @param smallint $actif
     */
    public function setActif($actif)
    {
        $this->actif = $actif;
    }

    /**
     * Get actif
     *
     * @return smallint
     */
    public function getActif()
    {
        return $this->actif;
    }

     /**
     * Set Users
     *
     * @param Korum\KBundle\Entity\Province $Users
     */
    public function setUsers(\Korum\KBundle\Entity\Users $users)
    {
        $this->users = $users;
    }

    /**
     * Get Users
     *
     * @return Korum\KBundle\Entity\Users
     */
    public function getUsers()
    {
        return $this->users;
    }

}

Does anyone have an idea of what happened ?


I tried to install the JSMSerializerBundle but event with Metadata library at version 1.1.
When I want to clear my cache, it failed with error :

See :
JMSSerializerBundle Installation : Catchable Fatal Error: Argument 1 passed to JMSSerializerBundle\Twig\SerializerExtension::__construct()

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T05:18:42+00:00Added an answer on June 10, 2026 at 5:18 am

    By default, json_encode only uses public properties.
    So it serialized the only public property of AGVote: $users. The content of $users was an instance of User; which public fields were serialized.

    You could work around these by adding a toArray() method to your entities, and then doing json_encode($entity->toArray()), but i highly recommend you to have a look and use the JMSSerializedBundle.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a problem while loading a UITableView on UITabBarController, i got this error
I have a problem returning/processing JSON data while calling $.get() function. Here's the code:
I have a problem using JSON and arrays. Here is my code: while($row =
I have problem while loading data into html select when users press or click
I have problem while using jquery maskedinput with asp.net textbox. I have a check
I have a problem while converting a string whose value is dd.mm.yyyy to DateTime
I have a problem while pasting my contents (or text) generated by Java code
I have a problem while executing a SSIS script component. To be honest I
I have a problem while scrolling images on tableview. I am getting a Signal
I have a problem while publishing on the Market. My application does not use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.