json ignore tag (“-”) not working on embedded sub structureHow 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

How to tell a function to use the default argument values?

Avoiding the "not like other girls" trope?

Why would the Red Woman birth a shadow if she worshipped the Lord of the Light?

In 'Revenger,' what does 'cove' come from?

Do UK voters know if their MP will be the Speaker of the House?

Assassin's bullet with mercury

How can I deal with my CEO asking me to hire someone with a higher salary than me, a co-founder?

Size of subfigure fitting its content (tikzpicture)

Mathematica command that allows it to read my intentions

Plagiarism or not?

How can I determine if the org that I'm currently connected to is a scratch org?

Examples of smooth manifolds admitting inbetween one and a continuum of complex structures

How much of data wrangling is a data scientist's job?

What's the in-universe reasoning behind sorcerers needing material components?

Am I breaking OOP practice with this architecture?

ssTTsSTtRrriinInnnnNNNIiinngg

What mechanic is there to disable a threat instead of killing it?

Avoiding direct proof while writing proof by induction

Intersection Puzzle

How could indestructible materials be used in power generation?

Is it logically or scientifically possible to artificially send energy to the body?

Detention in 1997

Expand and Contract

What is a romance in Latin?



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


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













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.4k1367101




      40.4k1367101










      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,3541118




                1,3541118





























                    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