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







                    Popular posts from this blog

                    Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

                    2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

                    Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme