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

                    Thal And Out Agency railway station See also References External links Navigation menuOfficial Web Site of Pakistan RailwaysArchivedOfficial Web Site of Pakistan Railwayseeexpanding ite

                    Understanding generators in Python2019 Community Moderator ElectionGenerator function not working pythonFor loop not executing two timesGenerators - Printing generated valuesWhy can a python generator only be used once?What exactly do generators do?What does the “yield” keyword do?What does “list comprehension” mean? How does it work and how can I use it?sklearn Kfold acces single fold instead of for loopIs a generator the callable? Which is the generator?Apply Border To Range Of Cells Using OpenpyxlCalling an external command in PythonWhat are metaclasses in Python?What is the difference between @staticmethod and @classmethod?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonHow can I safely create a nested directory in Python?Does Python have a ternary conditional operator?Understanding slice notationUnderstanding Python super() with __init__() methodsDoes Python have a string 'contains' substring method?

                    How can I change the color of pagination dots of UIPageControl?How to change UIPageControl dotsIs there a way to change page indicator dots colorCustomize dot with image of UIPageControl at index 0 of UIPageControlNo visible @interface for 'NSObject<PageControlDelegate>' declares the selector 'pageControlPageDidChange:'How to change the color of pagination dots in UIPageControl with a different color per pagepagecontrol indicator custom image instead of DefaultChanging the colour of UIPageControl dots in MonoTouchpagecontrol selectable page visibility color?Alternative way to load ViewControllers on a UIPageControlHow to set only layer.border-color for UIpage control dots in swiftHow can I develop for iPhone using a Windows development machine?How to change the name of an iOS app?UITableView - change section header coloruipagecontrol indicator(dot)issueCustom UIPageControl dots color not changingchange the interspace between UIPageControl dotsHow to change Status Bar text color in iOSHow can I change image tintColor in iOS and WatchKitUIPageControl dots with larger space in between each dotsHow to change the color of pagination dots in UIPageControl with a different color per page