JSON.deserialize return null values

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












1














I'm trying to Test my Rest Web Service class.
I want to simulate the process by taking a JSON and deserialize it to a class - Instead to create all the data by my self.



But for some reason - all my values after deserialization is null - Can someone please help me to understand why?



Json




"ContactJs":
"another_Id": "cjfv5g33k61ls7jdlf4353kjg",
"first_name": "2",
"last_name": " 2 ",
"first_name_english": "Tests2",
"last_name_english": "Tests22",
"email": "Tests2@Israeli.com",
"id_number": "01h11162t31f215",
"father_name": "fh",
"passport_number": "023117735",
"passport_issued_country": "USA",
"birthdate": "30/11/2001",
"mobile_phone": "05871336597",
"gender": "Female",
"contact_birth_country": "USA",
"country_origion_mother": "USA",
"country_origion_father": "USA",
"hed_ethnicity": "01",
"other_ethnicity": "fgh",
"immigrated_year": "2000",
"demographic_city": "123",
"no_promotion_interactions": true,
"international_area_code": "+972",
"residency_type": "1"




Class



public class ContactJs

public String another_Id;
public string first_name;
public string last_name;
public string first_name_english;
public string last_name_english;
public string email;
public string id_number;
public string passport_number;
public String passport_issued_country;
public String birthdate;
public string mobile_phone;
public String gender;
public string contact_birth_country;
public string country_origion_mother;
public string country_origion_father;
public string hed_ethnicity;
public string other_ethnicity;
public string immigrated_year;
public string demographic_city;
public Boolean no_promotion_interactions;
public String international_area_code;
public String residency_type;
public String father_name;



Deserialize



String jso = '"ContactJs": "another_Id": "cjfv5g33k61ls7jdlf4353kjg", "first_name": "2", "last_name": " 2 ", "first_name_english": "Tests2", "last_name_english": "Tests22", "email": "Tests2@Israeli.com", "id_number": "01h11162t31f215", "father_name": "fh", "passport_number": "023117735", "passport_issued_country": "ISR", "birthdate": "30/11/2001", "mobile_phone": "05871336597", "gender": "Female", "contact_birth_country": "ISR", "country_origion_mother": "USA", "country_origion_father": "ISR", "hed_ethnicity": "01", "other_ethnicity": "fgh", "immigrated_year": "2000", "demographic_city": "123", "no_promotion_interactions": true, "international_area_code": "+972", "residency_type": "1"';
ContactJs data = (ContactJs) JSON.deserialize(jso, ContactJs.class);

System.debug(data);


Output



ContactJs:[another_Id=null, birthdate=null,
contact_birth_country=null, country_origion_father=null,
country_origion_mother=null, demographic_city=null, email=null,
father_name=null, first_name=null, first_name_english=null,
gender=null, hed_ethnicity=null, id_number=null, immigrated_year=null,
international_area_code=null, last_name=null, last_name_english=null,
mobile_phone=null, no_promotion_interactions=null,
other_ethnicity=null, passport_issued_country=null,
passport_number=null, residency_type=null]









share|improve this question




























    1














    I'm trying to Test my Rest Web Service class.
    I want to simulate the process by taking a JSON and deserialize it to a class - Instead to create all the data by my self.



    But for some reason - all my values after deserialization is null - Can someone please help me to understand why?



    Json




    "ContactJs":
    "another_Id": "cjfv5g33k61ls7jdlf4353kjg",
    "first_name": "2",
    "last_name": " 2 ",
    "first_name_english": "Tests2",
    "last_name_english": "Tests22",
    "email": "Tests2@Israeli.com",
    "id_number": "01h11162t31f215",
    "father_name": "fh",
    "passport_number": "023117735",
    "passport_issued_country": "USA",
    "birthdate": "30/11/2001",
    "mobile_phone": "05871336597",
    "gender": "Female",
    "contact_birth_country": "USA",
    "country_origion_mother": "USA",
    "country_origion_father": "USA",
    "hed_ethnicity": "01",
    "other_ethnicity": "fgh",
    "immigrated_year": "2000",
    "demographic_city": "123",
    "no_promotion_interactions": true,
    "international_area_code": "+972",
    "residency_type": "1"




    Class



    public class ContactJs

    public String another_Id;
    public string first_name;
    public string last_name;
    public string first_name_english;
    public string last_name_english;
    public string email;
    public string id_number;
    public string passport_number;
    public String passport_issued_country;
    public String birthdate;
    public string mobile_phone;
    public String gender;
    public string contact_birth_country;
    public string country_origion_mother;
    public string country_origion_father;
    public string hed_ethnicity;
    public string other_ethnicity;
    public string immigrated_year;
    public string demographic_city;
    public Boolean no_promotion_interactions;
    public String international_area_code;
    public String residency_type;
    public String father_name;



    Deserialize



    String jso = '"ContactJs": "another_Id": "cjfv5g33k61ls7jdlf4353kjg", "first_name": "2", "last_name": " 2 ", "first_name_english": "Tests2", "last_name_english": "Tests22", "email": "Tests2@Israeli.com", "id_number": "01h11162t31f215", "father_name": "fh", "passport_number": "023117735", "passport_issued_country": "ISR", "birthdate": "30/11/2001", "mobile_phone": "05871336597", "gender": "Female", "contact_birth_country": "ISR", "country_origion_mother": "USA", "country_origion_father": "ISR", "hed_ethnicity": "01", "other_ethnicity": "fgh", "immigrated_year": "2000", "demographic_city": "123", "no_promotion_interactions": true, "international_area_code": "+972", "residency_type": "1"';
    ContactJs data = (ContactJs) JSON.deserialize(jso, ContactJs.class);

    System.debug(data);


    Output



    ContactJs:[another_Id=null, birthdate=null,
    contact_birth_country=null, country_origion_father=null,
    country_origion_mother=null, demographic_city=null, email=null,
    father_name=null, first_name=null, first_name_english=null,
    gender=null, hed_ethnicity=null, id_number=null, immigrated_year=null,
    international_area_code=null, last_name=null, last_name_english=null,
    mobile_phone=null, no_promotion_interactions=null,
    other_ethnicity=null, passport_issued_country=null,
    passport_number=null, residency_type=null]









    share|improve this question


























      1












      1








      1







      I'm trying to Test my Rest Web Service class.
      I want to simulate the process by taking a JSON and deserialize it to a class - Instead to create all the data by my self.



      But for some reason - all my values after deserialization is null - Can someone please help me to understand why?



      Json




      "ContactJs":
      "another_Id": "cjfv5g33k61ls7jdlf4353kjg",
      "first_name": "2",
      "last_name": " 2 ",
      "first_name_english": "Tests2",
      "last_name_english": "Tests22",
      "email": "Tests2@Israeli.com",
      "id_number": "01h11162t31f215",
      "father_name": "fh",
      "passport_number": "023117735",
      "passport_issued_country": "USA",
      "birthdate": "30/11/2001",
      "mobile_phone": "05871336597",
      "gender": "Female",
      "contact_birth_country": "USA",
      "country_origion_mother": "USA",
      "country_origion_father": "USA",
      "hed_ethnicity": "01",
      "other_ethnicity": "fgh",
      "immigrated_year": "2000",
      "demographic_city": "123",
      "no_promotion_interactions": true,
      "international_area_code": "+972",
      "residency_type": "1"




      Class



      public class ContactJs

      public String another_Id;
      public string first_name;
      public string last_name;
      public string first_name_english;
      public string last_name_english;
      public string email;
      public string id_number;
      public string passport_number;
      public String passport_issued_country;
      public String birthdate;
      public string mobile_phone;
      public String gender;
      public string contact_birth_country;
      public string country_origion_mother;
      public string country_origion_father;
      public string hed_ethnicity;
      public string other_ethnicity;
      public string immigrated_year;
      public string demographic_city;
      public Boolean no_promotion_interactions;
      public String international_area_code;
      public String residency_type;
      public String father_name;



      Deserialize



      String jso = '"ContactJs": "another_Id": "cjfv5g33k61ls7jdlf4353kjg", "first_name": "2", "last_name": " 2 ", "first_name_english": "Tests2", "last_name_english": "Tests22", "email": "Tests2@Israeli.com", "id_number": "01h11162t31f215", "father_name": "fh", "passport_number": "023117735", "passport_issued_country": "ISR", "birthdate": "30/11/2001", "mobile_phone": "05871336597", "gender": "Female", "contact_birth_country": "ISR", "country_origion_mother": "USA", "country_origion_father": "ISR", "hed_ethnicity": "01", "other_ethnicity": "fgh", "immigrated_year": "2000", "demographic_city": "123", "no_promotion_interactions": true, "international_area_code": "+972", "residency_type": "1"';
      ContactJs data = (ContactJs) JSON.deserialize(jso, ContactJs.class);

      System.debug(data);


      Output



      ContactJs:[another_Id=null, birthdate=null,
      contact_birth_country=null, country_origion_father=null,
      country_origion_mother=null, demographic_city=null, email=null,
      father_name=null, first_name=null, first_name_english=null,
      gender=null, hed_ethnicity=null, id_number=null, immigrated_year=null,
      international_area_code=null, last_name=null, last_name_english=null,
      mobile_phone=null, no_promotion_interactions=null,
      other_ethnicity=null, passport_issued_country=null,
      passport_number=null, residency_type=null]









      share|improve this question















      I'm trying to Test my Rest Web Service class.
      I want to simulate the process by taking a JSON and deserialize it to a class - Instead to create all the data by my self.



      But for some reason - all my values after deserialization is null - Can someone please help me to understand why?



      Json




      "ContactJs":
      "another_Id": "cjfv5g33k61ls7jdlf4353kjg",
      "first_name": "2",
      "last_name": " 2 ",
      "first_name_english": "Tests2",
      "last_name_english": "Tests22",
      "email": "Tests2@Israeli.com",
      "id_number": "01h11162t31f215",
      "father_name": "fh",
      "passport_number": "023117735",
      "passport_issued_country": "USA",
      "birthdate": "30/11/2001",
      "mobile_phone": "05871336597",
      "gender": "Female",
      "contact_birth_country": "USA",
      "country_origion_mother": "USA",
      "country_origion_father": "USA",
      "hed_ethnicity": "01",
      "other_ethnicity": "fgh",
      "immigrated_year": "2000",
      "demographic_city": "123",
      "no_promotion_interactions": true,
      "international_area_code": "+972",
      "residency_type": "1"




      Class



      public class ContactJs

      public String another_Id;
      public string first_name;
      public string last_name;
      public string first_name_english;
      public string last_name_english;
      public string email;
      public string id_number;
      public string passport_number;
      public String passport_issued_country;
      public String birthdate;
      public string mobile_phone;
      public String gender;
      public string contact_birth_country;
      public string country_origion_mother;
      public string country_origion_father;
      public string hed_ethnicity;
      public string other_ethnicity;
      public string immigrated_year;
      public string demographic_city;
      public Boolean no_promotion_interactions;
      public String international_area_code;
      public String residency_type;
      public String father_name;



      Deserialize



      String jso = '"ContactJs": "another_Id": "cjfv5g33k61ls7jdlf4353kjg", "first_name": "2", "last_name": " 2 ", "first_name_english": "Tests2", "last_name_english": "Tests22", "email": "Tests2@Israeli.com", "id_number": "01h11162t31f215", "father_name": "fh", "passport_number": "023117735", "passport_issued_country": "ISR", "birthdate": "30/11/2001", "mobile_phone": "05871336597", "gender": "Female", "contact_birth_country": "ISR", "country_origion_mother": "USA", "country_origion_father": "ISR", "hed_ethnicity": "01", "other_ethnicity": "fgh", "immigrated_year": "2000", "demographic_city": "123", "no_promotion_interactions": true, "international_area_code": "+972", "residency_type": "1"';
      ContactJs data = (ContactJs) JSON.deserialize(jso, ContactJs.class);

      System.debug(data);


      Output



      ContactJs:[another_Id=null, birthdate=null,
      contact_birth_country=null, country_origion_father=null,
      country_origion_mother=null, demographic_city=null, email=null,
      father_name=null, first_name=null, first_name_english=null,
      gender=null, hed_ethnicity=null, id_number=null, immigrated_year=null,
      international_area_code=null, last_name=null, last_name_english=null,
      mobile_phone=null, no_promotion_interactions=null,
      other_ethnicity=null, passport_issued_country=null,
      passport_number=null, residency_type=null]






      apex unit-test json deserialize






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 27 '18 at 14:18









      Community

      1




      1










      asked Dec 27 '18 at 9:48









      SalvationSalvation

      656




      656




















          1 Answer
          1






          active

          oldest

          votes


















          5














          Just remove ContactJs, You don't need to include class name.



          This should work



          String jso = ' "another_Id": "cjfv5g33k61ls7jdlf4353kjg", "first_name": "2", "last_name": " 2 ", "first_name_english": "Tests2", "last_name_english": "Tests22", "email": "Tests2@Israeli.com", "id_number": "01h11162t31f215", "father_name": "fh", "passport_number": "023117735", "passport_issued_country": "ISR", "birthdate": "30/11/2001", "mobile_phone": "05871336597", "gender": "Female", "contact_birth_country": "ISR", "country_origion_mother": "USA", "country_origion_father": "ISR", "hed_ethnicity": "01", "other_ethnicity": "fgh", "immigrated_year": "2000", "demographic_city": "123", "no_promotion_interactions": true, "international_area_code": "+972", "residency_type": "1"';
          ContactJs data = (ContactJs) JSON.deserialize(jso, ContactJs.class);

          System.debug(data);



          15:21:30:003 USER_DEBUG
          [32]|DEBUG|ContactJs:[another_Id=cjfv5g33k61ls7jdlf4353kjg,
          birthdate=30/11/2001, contact_birth_country=ISR,
          country_origion_father=ISR, country_origion_mother=USA,
          demographic_city=123, email=Tests2@Israeli.com, father_name=fh,
          first_name=2, first_name_english=Tests2, gender=Female,
          hed_ethnicity=01, id_number=01h11162t31f215, immigrated_year=2000,
          international_area_code=+972, last_name= 2 ,
          last_name_english=Tests22, mobile_phone=05871336597,
          no_promotion_interactions=true, other_ethnicity=fgh,
          passport_issued_country=ISR, passport_number=023117735,
          residency_type=1]







          share|improve this answer




















            Your Answer








            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "459"
            ;
            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: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            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%2fsalesforce.stackexchange.com%2fquestions%2f244734%2fjson-deserialize-return-null-values%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









            5














            Just remove ContactJs, You don't need to include class name.



            This should work



            String jso = ' "another_Id": "cjfv5g33k61ls7jdlf4353kjg", "first_name": "2", "last_name": " 2 ", "first_name_english": "Tests2", "last_name_english": "Tests22", "email": "Tests2@Israeli.com", "id_number": "01h11162t31f215", "father_name": "fh", "passport_number": "023117735", "passport_issued_country": "ISR", "birthdate": "30/11/2001", "mobile_phone": "05871336597", "gender": "Female", "contact_birth_country": "ISR", "country_origion_mother": "USA", "country_origion_father": "ISR", "hed_ethnicity": "01", "other_ethnicity": "fgh", "immigrated_year": "2000", "demographic_city": "123", "no_promotion_interactions": true, "international_area_code": "+972", "residency_type": "1"';
            ContactJs data = (ContactJs) JSON.deserialize(jso, ContactJs.class);

            System.debug(data);



            15:21:30:003 USER_DEBUG
            [32]|DEBUG|ContactJs:[another_Id=cjfv5g33k61ls7jdlf4353kjg,
            birthdate=30/11/2001, contact_birth_country=ISR,
            country_origion_father=ISR, country_origion_mother=USA,
            demographic_city=123, email=Tests2@Israeli.com, father_name=fh,
            first_name=2, first_name_english=Tests2, gender=Female,
            hed_ethnicity=01, id_number=01h11162t31f215, immigrated_year=2000,
            international_area_code=+972, last_name= 2 ,
            last_name_english=Tests22, mobile_phone=05871336597,
            no_promotion_interactions=true, other_ethnicity=fgh,
            passport_issued_country=ISR, passport_number=023117735,
            residency_type=1]







            share|improve this answer

























              5














              Just remove ContactJs, You don't need to include class name.



              This should work



              String jso = ' "another_Id": "cjfv5g33k61ls7jdlf4353kjg", "first_name": "2", "last_name": " 2 ", "first_name_english": "Tests2", "last_name_english": "Tests22", "email": "Tests2@Israeli.com", "id_number": "01h11162t31f215", "father_name": "fh", "passport_number": "023117735", "passport_issued_country": "ISR", "birthdate": "30/11/2001", "mobile_phone": "05871336597", "gender": "Female", "contact_birth_country": "ISR", "country_origion_mother": "USA", "country_origion_father": "ISR", "hed_ethnicity": "01", "other_ethnicity": "fgh", "immigrated_year": "2000", "demographic_city": "123", "no_promotion_interactions": true, "international_area_code": "+972", "residency_type": "1"';
              ContactJs data = (ContactJs) JSON.deserialize(jso, ContactJs.class);

              System.debug(data);



              15:21:30:003 USER_DEBUG
              [32]|DEBUG|ContactJs:[another_Id=cjfv5g33k61ls7jdlf4353kjg,
              birthdate=30/11/2001, contact_birth_country=ISR,
              country_origion_father=ISR, country_origion_mother=USA,
              demographic_city=123, email=Tests2@Israeli.com, father_name=fh,
              first_name=2, first_name_english=Tests2, gender=Female,
              hed_ethnicity=01, id_number=01h11162t31f215, immigrated_year=2000,
              international_area_code=+972, last_name= 2 ,
              last_name_english=Tests22, mobile_phone=05871336597,
              no_promotion_interactions=true, other_ethnicity=fgh,
              passport_issued_country=ISR, passport_number=023117735,
              residency_type=1]







              share|improve this answer























                5












                5








                5






                Just remove ContactJs, You don't need to include class name.



                This should work



                String jso = ' "another_Id": "cjfv5g33k61ls7jdlf4353kjg", "first_name": "2", "last_name": " 2 ", "first_name_english": "Tests2", "last_name_english": "Tests22", "email": "Tests2@Israeli.com", "id_number": "01h11162t31f215", "father_name": "fh", "passport_number": "023117735", "passport_issued_country": "ISR", "birthdate": "30/11/2001", "mobile_phone": "05871336597", "gender": "Female", "contact_birth_country": "ISR", "country_origion_mother": "USA", "country_origion_father": "ISR", "hed_ethnicity": "01", "other_ethnicity": "fgh", "immigrated_year": "2000", "demographic_city": "123", "no_promotion_interactions": true, "international_area_code": "+972", "residency_type": "1"';
                ContactJs data = (ContactJs) JSON.deserialize(jso, ContactJs.class);

                System.debug(data);



                15:21:30:003 USER_DEBUG
                [32]|DEBUG|ContactJs:[another_Id=cjfv5g33k61ls7jdlf4353kjg,
                birthdate=30/11/2001, contact_birth_country=ISR,
                country_origion_father=ISR, country_origion_mother=USA,
                demographic_city=123, email=Tests2@Israeli.com, father_name=fh,
                first_name=2, first_name_english=Tests2, gender=Female,
                hed_ethnicity=01, id_number=01h11162t31f215, immigrated_year=2000,
                international_area_code=+972, last_name= 2 ,
                last_name_english=Tests22, mobile_phone=05871336597,
                no_promotion_interactions=true, other_ethnicity=fgh,
                passport_issued_country=ISR, passport_number=023117735,
                residency_type=1]







                share|improve this answer












                Just remove ContactJs, You don't need to include class name.



                This should work



                String jso = ' "another_Id": "cjfv5g33k61ls7jdlf4353kjg", "first_name": "2", "last_name": " 2 ", "first_name_english": "Tests2", "last_name_english": "Tests22", "email": "Tests2@Israeli.com", "id_number": "01h11162t31f215", "father_name": "fh", "passport_number": "023117735", "passport_issued_country": "ISR", "birthdate": "30/11/2001", "mobile_phone": "05871336597", "gender": "Female", "contact_birth_country": "ISR", "country_origion_mother": "USA", "country_origion_father": "ISR", "hed_ethnicity": "01", "other_ethnicity": "fgh", "immigrated_year": "2000", "demographic_city": "123", "no_promotion_interactions": true, "international_area_code": "+972", "residency_type": "1"';
                ContactJs data = (ContactJs) JSON.deserialize(jso, ContactJs.class);

                System.debug(data);



                15:21:30:003 USER_DEBUG
                [32]|DEBUG|ContactJs:[another_Id=cjfv5g33k61ls7jdlf4353kjg,
                birthdate=30/11/2001, contact_birth_country=ISR,
                country_origion_father=ISR, country_origion_mother=USA,
                demographic_city=123, email=Tests2@Israeli.com, father_name=fh,
                first_name=2, first_name_english=Tests2, gender=Female,
                hed_ethnicity=01, id_number=01h11162t31f215, immigrated_year=2000,
                international_area_code=+972, last_name= 2 ,
                last_name_english=Tests22, mobile_phone=05871336597,
                no_promotion_interactions=true, other_ethnicity=fgh,
                passport_issued_country=ISR, passport_number=023117735,
                residency_type=1]








                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 27 '18 at 9:52









                rahul gawalerahul gawale

                639216




                639216



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Salesforce Stack Exchange!


                    • 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%2fsalesforce.stackexchange.com%2fquestions%2f244734%2fjson-deserialize-return-null-values%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

                    How to check contact read email or not when send email to Individual?

                    Displaying single band from multi-band raster using QGIS

                    How many registers does an x86_64 CPU actually have?