You need to sign in to do that
Don't have an account?
mysteriousaura
Pros and Cons typed vs untyped JSON de-serializers
Hi,
I was curious if anyone has any opinion about using typed vs untyped JSON de-serializers in salesforce. What are the pros and cons specially from a ISV or product dev perspective.
I was curious if anyone has any opinion about using typed vs untyped JSON de-serializers in salesforce. What are the pros and cons specially from a ISV or product dev perspective.
Also, writing Apex tests against typed JSON work is much easier. This is because you can quickly generate a new class instance and pass that around in your test. With the deserialized version you are passing around raw JSON all the time. Also, if your JSON structure changes you can update the typed data and you'll instantly get Apex compile errors if you miss something where as with untyped you may not know until you hit that path of your code.
All Answers
[1] http://blog.deadlypenguin.com/blog/2015/11/30/json-deserialization-in-salesforce/
[2] https://github.com/apex-lodash/lo
For most part, I am pretty sure of what fields will be in the JSON, but need to make sure it will scale in the long run! I have worked with typed before and it makes it super easy but the counter argument being what if the JSON changes or we add more fields. I will have to compile all the apex classes again - does not work so well when you are developing a product?
Do you still think you would choose typed vs untyped? Is untyped strictly when you have no idea what the JSON looks like? My experience with untyped is that you still have to kind of know some sort of structure, you can't make it completely dynamic! Is that true?
Also, writing Apex tests against typed JSON work is much easier. This is because you can quickly generate a new class instance and pass that around in your test. With the deserialized version you are passing around raw JSON all the time. Also, if your JSON structure changes you can update the typed data and you'll instantly get Apex compile errors if you miss something where as with untyped you may not know until you hit that path of your code.
This helps!