2

I am doing a callout to RESTful web service and following the example given here in Integration workbook

My actual requirement is to query for some values and post these values in JSON to webservice.

1) To prepare JSON, I see 2 options: JSONGenerator and Serialize. The difference I noted among them is I can format JSON structure in JSON Generator. Is there any other major difference like size of the JSON etc.

2) While using JsonGenerator, I can write my own field labels in JSON using writeStringField but If I am going for serialize, I need to declare all field labels with the datatype they are supposed to hold in a separate class. Is it also necessary to declare a separate class to hold these field labels while using JSONGenerator ?

3) Since I am posting values to external webservice, should I use {get;set;}

Thanks

2
  • 1
    others will give longer answer, but No to #3
    – cropredy
    Commented Aug 7, 2015 at 21:21
  • 2
    The generator allows for more precise control and for my purposes at least is overly complex for most tasks. Serializing a class is much easier and quicker. There are limitations on the class though like the inability to use certain property names etc. Class is also easier to maintain and update. I would say go class/serialize first and if that presents roadblocks then use the generator. and no to #2 it is not necessary to use a class with the generator
    – Eric
    Commented Aug 8, 2015 at 0:00

1 Answer 1

1

Making comment an answer. If someone wants to add a more elaborate answer......

The generator allows for more precise control and for my purposes at least is overly complex for most tasks.

Serializing a class is much easier and quicker.

There are limitations on the class though like the inability to use certain property names etc.

Class is also easier to maintain and update.

I would say go class/serialize first and if that presents roadblocks then use the generator. and no to #2 it is not necessary to use a class with the generator

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .