Timeline for How to handle multiple type of json in one parser class?
Current License: CC BY-SA 4.0
12 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Sep 18, 2018 at 13:36 | comment | added | Jayant Das |
The issue is with your JSON. If Services is supposed to be an array of values, then if at all it is present in the JSON, then it should be sent as Services : [] and not as null. However in your question, it seemed like that array never is sent in the JSON. But in any case, as long as your JSON sends the data based on its schema, your parsing will absolutely work fine.
|
|
Sep 18, 2018 at 13:16 | comment | added | shukla yogesh | The reason this is happening because json is having "" for services instead of list in case of failure. So I have to either remove that element from json then it worked. What would you suggest? I guess if I am getting "" instead of expected format.. then this will not work and no way to cover this. Please suggest | |
Sep 18, 2018 at 13:04 | comment | added | shukla yogesh | I got the class from the json2apex.. It works fine when all attributes are there but for this scenario it fails. | |
Sep 18, 2018 at 12:57 | comment | added | Jayant Das | You should review your implementation and the JSON to make sure it aligns to your wrapper class. Because you don't have the wrapper class in here, and the one I posted in the example works perfectly fine without the attribute being present in the JSON. | |
Sep 18, 2018 at 12:52 | comment | added | shukla yogesh | expected list of services found "" like that | |
Sep 18, 2018 at 12:11 | comment | added | Jayant Das | And what is the error? | |
Sep 18, 2018 at 11:54 | comment | added | shukla yogesh | It fails in this line itself so I can't perform check. Subscription subsc = (Subscription)JSON.deserialize(jsonStr, Subscription.class); | |
Sep 17, 2018 at 13:36 | comment | added | Jayant Das | And I added a sample "working example". So you should try the parsing first -- it won't fail. | |
Sep 17, 2018 at 13:35 | history | edited | Jayant Das | CC BY-SA 4.0 |
added 339 characters in body
|
Sep 17, 2018 at 13:29 | comment | added | Jayant Das |
Have you tried parsing already? I can tell you if the JSON does not contain an attribute in the message, and that when you deserialize the response, your List<Services> will just be initialized with null .
|
|
Sep 17, 2018 at 13:28 | comment | added | shukla yogesh | Yes, that's my problem. I can't see orderstatus because parsing will fail due to list<services> not found. Any alternative for that ? | |
Sep 17, 2018 at 13:25 | history | answered | Jayant Das | CC BY-SA 4.0 |