json ignore tag (“-”) not working on embedded sub structure Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!How do I iterate over a JSON structure?Jackson with JSON: Unrecognized field, not marked as ignorableIgnoring new fields on JSON objects using JacksonJSON.stringify, avoid TypeError: Converting circular structure to JSONjson decode key typesUnmarshalling JSON into Go interfaceStruct for JSON ResponseIs Go able to unmarshal to map[string][]interface?Golang decoding JSON into slice with one string and one float64GoLang structure doesn't unmarshal properly when using a custom unmarshal for a nested struct

Combinatorics problem on counting.

Can the Great Weapon Master feat's "Power Attack" apply to attacks from the Spiritual Weapon spell?

ArcGIS Pro Python arcpy.CreatePersonalGDB_management

Is CEO the "profession" with the most psychopaths?

What's the meaning of "fortified infraction restraint"?

How to install press fit bottom bracket into new frame

Disembodied hand growing fangs

Maximum summed subsequences with non-adjacent items

How do I use the new nonlinear finite element in Mathematica 12 for this equation?

Can an alien society believe that their star system is the universe?

How to compare two different files line by line in unix?

AppleTVs create a chatty alternate WiFi network

How often does castling occur in grandmaster games?

Denied boarding although I have proper visa and documentation. To whom should I make a complaint?

Why is it faster to reheat something than it is to cook it?

Drawing without replacement: why is the order of draw irrelevant?

Most bit efficient text communication method?

Has negative voting ever been officially implemented in elections, or seriously proposed, or even studied?

Putting class ranking in CV, but against dept guidelines

A term for a woman complaining about things/begging in a cute/childish way

Should I use a zero-interest credit card for a large one-time purchase?

Generate an RGB colour grid

An adverb for when you're not exaggerating

Why do we bend a book to keep it straight?



json ignore tag (“-”) not working on embedded sub structure



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!How do I iterate over a JSON structure?Jackson with JSON: Unrecognized field, not marked as ignorableIgnoring new fields on JSON objects using JacksonJSON.stringify, avoid TypeError: Converting circular structure to JSONjson decode key typesUnmarshalling JSON into Go interfaceStruct for JSON ResponseIs Go able to unmarshal to map[string][]interface?Golang decoding JSON into slice with one string and one float64GoLang structure doesn't unmarshal properly when using a custom unmarshal for a nested struct



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








2















I have been reading a lot of related questions but could not find anything that actually fit my problem. I am trying to unmarshall a complex object.



type DC struct 

//other fields
ReplenishmentData map[string]ProductReplenishment `bson:"-"`
//other fields


type ProductReplenishment struct
//Other fields
SafetyStockInDay int `json:"SafetyStockInDay" bson:"SafetyStockInDay"`
AlreadyOrderedQuantityForReplenishment *map[float64]*UnitQuantity `json:"-" bson:"-"`
//Other fields



Lets say I decode the following json:




"ReplenishmentData":
"000822-099":
"SafetyStockInDay": 7
,
"001030-001":
"SafetyStockInDay": 7





Into a structure instance hierachy in which the AlreadyOrderedQuantityForReplenishment is not empty, after decoding this field will be set to and empty map, overriding the initial value.



Why is the decoder not ignore the field all together as specified in the docs? Am I missing something?



Thanks a lot for any help,



Adding screenshot of inspector before (first) / after (second) if that can help



beforeafter










share|improve this question






























    2















    I have been reading a lot of related questions but could not find anything that actually fit my problem. I am trying to unmarshall a complex object.



    type DC struct 

    //other fields
    ReplenishmentData map[string]ProductReplenishment `bson:"-"`
    //other fields


    type ProductReplenishment struct
    //Other fields
    SafetyStockInDay int `json:"SafetyStockInDay" bson:"SafetyStockInDay"`
    AlreadyOrderedQuantityForReplenishment *map[float64]*UnitQuantity `json:"-" bson:"-"`
    //Other fields



    Lets say I decode the following json:




    "ReplenishmentData":
    "000822-099":
    "SafetyStockInDay": 7
    ,
    "001030-001":
    "SafetyStockInDay": 7





    Into a structure instance hierachy in which the AlreadyOrderedQuantityForReplenishment is not empty, after decoding this field will be set to and empty map, overriding the initial value.



    Why is the decoder not ignore the field all together as specified in the docs? Am I missing something?



    Thanks a lot for any help,



    Adding screenshot of inspector before (first) / after (second) if that can help



    beforeafter










    share|improve this question


























      2












      2








      2








      I have been reading a lot of related questions but could not find anything that actually fit my problem. I am trying to unmarshall a complex object.



      type DC struct 

      //other fields
      ReplenishmentData map[string]ProductReplenishment `bson:"-"`
      //other fields


      type ProductReplenishment struct
      //Other fields
      SafetyStockInDay int `json:"SafetyStockInDay" bson:"SafetyStockInDay"`
      AlreadyOrderedQuantityForReplenishment *map[float64]*UnitQuantity `json:"-" bson:"-"`
      //Other fields



      Lets say I decode the following json:




      "ReplenishmentData":
      "000822-099":
      "SafetyStockInDay": 7
      ,
      "001030-001":
      "SafetyStockInDay": 7





      Into a structure instance hierachy in which the AlreadyOrderedQuantityForReplenishment is not empty, after decoding this field will be set to and empty map, overriding the initial value.



      Why is the decoder not ignore the field all together as specified in the docs? Am I missing something?



      Thanks a lot for any help,



      Adding screenshot of inspector before (first) / after (second) if that can help



      beforeafter










      share|improve this question
















      I have been reading a lot of related questions but could not find anything that actually fit my problem. I am trying to unmarshall a complex object.



      type DC struct 

      //other fields
      ReplenishmentData map[string]ProductReplenishment `bson:"-"`
      //other fields


      type ProductReplenishment struct
      //Other fields
      SafetyStockInDay int `json:"SafetyStockInDay" bson:"SafetyStockInDay"`
      AlreadyOrderedQuantityForReplenishment *map[float64]*UnitQuantity `json:"-" bson:"-"`
      //Other fields



      Lets say I decode the following json:




      "ReplenishmentData":
      "000822-099":
      "SafetyStockInDay": 7
      ,
      "001030-001":
      "SafetyStockInDay": 7





      Into a structure instance hierachy in which the AlreadyOrderedQuantityForReplenishment is not empty, after decoding this field will be set to and empty map, overriding the initial value.



      Why is the decoder not ignore the field all together as specified in the docs? Am I missing something?



      Thanks a lot for any help,



      Adding screenshot of inspector before (first) / after (second) if that can help



      beforeafter







      json go nested tags unmarshalling






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 8 at 22:40









      Flimzy

      40.9k1367101




      40.9k1367101










      asked Mar 8 at 20:14









      Lou-adrienLou-adrien

      415




      415






















          1 Answer
          1






          active

          oldest

          votes


















          0














          Your problem is not related to embedded structs - the same issue would occur with a regular struct.



          Encoders will skip encoding struct fields marked with the tag qualifier "-".
          Decoders when initializing a struct, will use the zero-value for any field that is not initialized via the decoding process. So your map will he initialized to a nil (empty) map.



          If you want to preserve settings you'd need to write your own (JSON or BSON) marshaler (doable - but not trivial). Or it may be just as simpler to just restore any zero-values after the decoding process.






          share|improve this answer

























            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',
            autoActivateHeartbeat: false,
            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%2f55070406%2fjson-ignore-tag-not-working-on-embedded-sub-structure%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Your problem is not related to embedded structs - the same issue would occur with a regular struct.



            Encoders will skip encoding struct fields marked with the tag qualifier "-".
            Decoders when initializing a struct, will use the zero-value for any field that is not initialized via the decoding process. So your map will he initialized to a nil (empty) map.



            If you want to preserve settings you'd need to write your own (JSON or BSON) marshaler (doable - but not trivial). Or it may be just as simpler to just restore any zero-values after the decoding process.






            share|improve this answer





























              0














              Your problem is not related to embedded structs - the same issue would occur with a regular struct.



              Encoders will skip encoding struct fields marked with the tag qualifier "-".
              Decoders when initializing a struct, will use the zero-value for any field that is not initialized via the decoding process. So your map will he initialized to a nil (empty) map.



              If you want to preserve settings you'd need to write your own (JSON or BSON) marshaler (doable - but not trivial). Or it may be just as simpler to just restore any zero-values after the decoding process.






              share|improve this answer



























                0












                0








                0







                Your problem is not related to embedded structs - the same issue would occur with a regular struct.



                Encoders will skip encoding struct fields marked with the tag qualifier "-".
                Decoders when initializing a struct, will use the zero-value for any field that is not initialized via the decoding process. So your map will he initialized to a nil (empty) map.



                If you want to preserve settings you'd need to write your own (JSON or BSON) marshaler (doable - but not trivial). Or it may be just as simpler to just restore any zero-values after the decoding process.






                share|improve this answer















                Your problem is not related to embedded structs - the same issue would occur with a regular struct.



                Encoders will skip encoding struct fields marked with the tag qualifier "-".
                Decoders when initializing a struct, will use the zero-value for any field that is not initialized via the decoding process. So your map will he initialized to a nil (empty) map.



                If you want to preserve settings you'd need to write your own (JSON or BSON) marshaler (doable - but not trivial). Or it may be just as simpler to just restore any zero-values after the decoding process.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Mar 8 at 23:31

























                answered Mar 8 at 20:37









                colminatorcolminator

                1,5961320




                1,5961320





























                    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.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55070406%2fjson-ignore-tag-not-working-on-embedded-sub-structure%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

                    AWS Lex not identifying response if by a variable The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceEnforcing custom enumeration in AWS LEX for slot valuesHow to give response based on user response in Amazon Lex?Intercepting AWS Lambda Response to a AWS Lex QueryLex chat bot error: Reached second execution of fulfillment lambda on the same utteranceamazon lex showing invalid responseLambda response send back to Lex slot?Response card in Amazon lexAmazon Lex - Lambda response return HTML to botHow can I solve 424 (Failed Dependency) (python) obtained from Amazon lex?

                    Алба-Юлія

                    Захаров Федір Захарович