Change serialized property name in Symfony serialisation











up vote
1
down vote

favorite












I'm using Symfony serializer. It works well.



use SymfonyComponentSerializerAnnotationGroups;

/**
*
* @Groups({"default", "notification"})
*/
public function getUser()
{
...
}


Is it possible serialise property as another name?
So I want to use getUser in framework, but property should named as profile in serialised json.



How I can do that?










share|improve this question


























    up vote
    1
    down vote

    favorite












    I'm using Symfony serializer. It works well.



    use SymfonyComponentSerializerAnnotationGroups;

    /**
    *
    * @Groups({"default", "notification"})
    */
    public function getUser()
    {
    ...
    }


    Is it possible serialise property as another name?
    So I want to use getUser in framework, but property should named as profile in serialised json.



    How I can do that?










    share|improve this question
























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I'm using Symfony serializer. It works well.



      use SymfonyComponentSerializerAnnotationGroups;

      /**
      *
      * @Groups({"default", "notification"})
      */
      public function getUser()
      {
      ...
      }


      Is it possible serialise property as another name?
      So I want to use getUser in framework, but property should named as profile in serialised json.



      How I can do that?










      share|improve this question













      I'm using Symfony serializer. It works well.



      use SymfonyComponentSerializerAnnotationGroups;

      /**
      *
      * @Groups({"default", "notification"})
      */
      public function getUser()
      {
      ...
      }


      Is it possible serialise property as another name?
      So I want to use getUser in framework, but property should named as profile in serialised json.



      How I can do that?







      php symfony






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 16 '17 at 3:24









      indapublic

      1,11152341




      1,11152341
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          3
          down vote



          accepted










          Edit 19-11-2018, this feature is now available since Symfony 4.2:



          /**
          * @SerializedName("some_name")
          */
          private $lastName;


          More information in the doc.



          Thanks to Sodj for the reminder.





          You can use a custom name converter for that purpose. Every information to achieve this are in this part of the doc.



          There is also an issue opened to override property name of the serialized object directly with annotations https://github.com/symfony/symfony/issues/15171






          share|improve this answer























          • Thanks. I'll try to inspect it.
            – indapublic
            Dec 17 '17 at 12:52










          • Ok. So Symfony serialise not contain @SerializedName feature. So I need to override rules for converter. It's not comfortably
            – indapublic
            Dec 18 '17 at 10:46






          • 1




            Now you can use serialized_name in model serialize config
            – Sodj
            Nov 18 at 14:05


















          up vote
          1
          down vote













          Did you tried, like for JMSserializer, this annotation :
          @SerializedName("changed_name") - https://jmsyst.com/libs/serializer/master/reference/annotations#serializedname ?






          share|improve this answer





















          • I'm tried it before as @SerializerSerializedName("foo") but it's not works. btw, I forgot mention symfony version. I'm using 3.4
            – indapublic
            Dec 17 '17 at 12:50










          • Symfony serialiser not contain @SerializedName feature.
            – indapublic
            Dec 18 '17 at 10:47











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f47842244%2fchange-serialized-property-name-in-symfony-serialisation%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          3
          down vote



          accepted










          Edit 19-11-2018, this feature is now available since Symfony 4.2:



          /**
          * @SerializedName("some_name")
          */
          private $lastName;


          More information in the doc.



          Thanks to Sodj for the reminder.





          You can use a custom name converter for that purpose. Every information to achieve this are in this part of the doc.



          There is also an issue opened to override property name of the serialized object directly with annotations https://github.com/symfony/symfony/issues/15171






          share|improve this answer























          • Thanks. I'll try to inspect it.
            – indapublic
            Dec 17 '17 at 12:52










          • Ok. So Symfony serialise not contain @SerializedName feature. So I need to override rules for converter. It's not comfortably
            – indapublic
            Dec 18 '17 at 10:46






          • 1




            Now you can use serialized_name in model serialize config
            – Sodj
            Nov 18 at 14:05















          up vote
          3
          down vote



          accepted










          Edit 19-11-2018, this feature is now available since Symfony 4.2:



          /**
          * @SerializedName("some_name")
          */
          private $lastName;


          More information in the doc.



          Thanks to Sodj for the reminder.





          You can use a custom name converter for that purpose. Every information to achieve this are in this part of the doc.



          There is also an issue opened to override property name of the serialized object directly with annotations https://github.com/symfony/symfony/issues/15171






          share|improve this answer























          • Thanks. I'll try to inspect it.
            – indapublic
            Dec 17 '17 at 12:52










          • Ok. So Symfony serialise not contain @SerializedName feature. So I need to override rules for converter. It's not comfortably
            – indapublic
            Dec 18 '17 at 10:46






          • 1




            Now you can use serialized_name in model serialize config
            – Sodj
            Nov 18 at 14:05













          up vote
          3
          down vote



          accepted







          up vote
          3
          down vote



          accepted






          Edit 19-11-2018, this feature is now available since Symfony 4.2:



          /**
          * @SerializedName("some_name")
          */
          private $lastName;


          More information in the doc.



          Thanks to Sodj for the reminder.





          You can use a custom name converter for that purpose. Every information to achieve this are in this part of the doc.



          There is also an issue opened to override property name of the serialized object directly with annotations https://github.com/symfony/symfony/issues/15171






          share|improve this answer














          Edit 19-11-2018, this feature is now available since Symfony 4.2:



          /**
          * @SerializedName("some_name")
          */
          private $lastName;


          More information in the doc.



          Thanks to Sodj for the reminder.





          You can use a custom name converter for that purpose. Every information to achieve this are in this part of the doc.



          There is also an issue opened to override property name of the serialized object directly with annotations https://github.com/symfony/symfony/issues/15171







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 19 at 19:57

























          answered Dec 16 '17 at 8:52









          Benoit Galati

          30315




          30315












          • Thanks. I'll try to inspect it.
            – indapublic
            Dec 17 '17 at 12:52










          • Ok. So Symfony serialise not contain @SerializedName feature. So I need to override rules for converter. It's not comfortably
            – indapublic
            Dec 18 '17 at 10:46






          • 1




            Now you can use serialized_name in model serialize config
            – Sodj
            Nov 18 at 14:05


















          • Thanks. I'll try to inspect it.
            – indapublic
            Dec 17 '17 at 12:52










          • Ok. So Symfony serialise not contain @SerializedName feature. So I need to override rules for converter. It's not comfortably
            – indapublic
            Dec 18 '17 at 10:46






          • 1




            Now you can use serialized_name in model serialize config
            – Sodj
            Nov 18 at 14:05
















          Thanks. I'll try to inspect it.
          – indapublic
          Dec 17 '17 at 12:52




          Thanks. I'll try to inspect it.
          – indapublic
          Dec 17 '17 at 12:52












          Ok. So Symfony serialise not contain @SerializedName feature. So I need to override rules for converter. It's not comfortably
          – indapublic
          Dec 18 '17 at 10:46




          Ok. So Symfony serialise not contain @SerializedName feature. So I need to override rules for converter. It's not comfortably
          – indapublic
          Dec 18 '17 at 10:46




          1




          1




          Now you can use serialized_name in model serialize config
          – Sodj
          Nov 18 at 14:05




          Now you can use serialized_name in model serialize config
          – Sodj
          Nov 18 at 14:05












          up vote
          1
          down vote













          Did you tried, like for JMSserializer, this annotation :
          @SerializedName("changed_name") - https://jmsyst.com/libs/serializer/master/reference/annotations#serializedname ?






          share|improve this answer





















          • I'm tried it before as @SerializerSerializedName("foo") but it's not works. btw, I forgot mention symfony version. I'm using 3.4
            – indapublic
            Dec 17 '17 at 12:50










          • Symfony serialiser not contain @SerializedName feature.
            – indapublic
            Dec 18 '17 at 10:47















          up vote
          1
          down vote













          Did you tried, like for JMSserializer, this annotation :
          @SerializedName("changed_name") - https://jmsyst.com/libs/serializer/master/reference/annotations#serializedname ?






          share|improve this answer





















          • I'm tried it before as @SerializerSerializedName("foo") but it's not works. btw, I forgot mention symfony version. I'm using 3.4
            – indapublic
            Dec 17 '17 at 12:50










          • Symfony serialiser not contain @SerializedName feature.
            – indapublic
            Dec 18 '17 at 10:47













          up vote
          1
          down vote










          up vote
          1
          down vote









          Did you tried, like for JMSserializer, this annotation :
          @SerializedName("changed_name") - https://jmsyst.com/libs/serializer/master/reference/annotations#serializedname ?






          share|improve this answer












          Did you tried, like for JMSserializer, this annotation :
          @SerializedName("changed_name") - https://jmsyst.com/libs/serializer/master/reference/annotations#serializedname ?







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 16 '17 at 8:41









          Dujardin Emmanuel

          343




          343












          • I'm tried it before as @SerializerSerializedName("foo") but it's not works. btw, I forgot mention symfony version. I'm using 3.4
            – indapublic
            Dec 17 '17 at 12:50










          • Symfony serialiser not contain @SerializedName feature.
            – indapublic
            Dec 18 '17 at 10:47


















          • I'm tried it before as @SerializerSerializedName("foo") but it's not works. btw, I forgot mention symfony version. I'm using 3.4
            – indapublic
            Dec 17 '17 at 12:50










          • Symfony serialiser not contain @SerializedName feature.
            – indapublic
            Dec 18 '17 at 10:47
















          I'm tried it before as @SerializerSerializedName("foo") but it's not works. btw, I forgot mention symfony version. I'm using 3.4
          – indapublic
          Dec 17 '17 at 12:50




          I'm tried it before as @SerializerSerializedName("foo") but it's not works. btw, I forgot mention symfony version. I'm using 3.4
          – indapublic
          Dec 17 '17 at 12:50












          Symfony serialiser not contain @SerializedName feature.
          – indapublic
          Dec 18 '17 at 10:47




          Symfony serialiser not contain @SerializedName feature.
          – indapublic
          Dec 18 '17 at 10:47


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f47842244%2fchange-serialized-property-name-in-symfony-serialisation%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Create new schema in PostgreSQL using DBeaver

          Deepest pit of an array with Javascript: test on Codility

          Costa Masnaga