2

I have an exceptional case. My json contains key with a space in it. Since the json is provided by a third party and used widely,i cannot change the incoming json. How can i de-serialize this? Example is below

Assume i have a class like below..

class b{
    Integer a;
}

How can i structure the above class to deserialize the below json. ?

System.debug(Json.deserialize('{"a b":1}', b.class));
2

If you use the deserializeUntyped() method you could get the JSON string converted into a map<String,Object>, and then get the property value with that string key.

Map<String,Object> apexmap = (Map<String, Object>) JSON.deserializeUntyped('{"a b":1}');

system.debug(apexmap.get('a b'));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.