Activity Forums Salesforce® Discussions What is the actual use of Serialization and Deserialization of a JSON?

  • PRANAV

    Member
    March 19, 2018 at 1:56 pm

    Hi Kapil,
    Deserializes the specified JSON string into an Apex object of the specified type.
    Serializes Apex objects into JSON content.

    If you didn't serialize the object into JSON, then the object would not be in a format that the consumer (the system who did the request) would understand. The purpose of serializing it into JSON is so that the message will be a format that can be understood and from there, deserialize it into an object type that makes sense for the consumer.

    Hope this helps you.

  • Parul

    Member
    September 18, 2018 at 7:58 pm

    Hi

    JSON is a format that encodes objects in a string. Serialization means to convert an object into that string, and deserialization is its inverse operation.

    When transmitting data or storing them in a file, the data are required to be byte strings, but complex objects are seldom in this format. Serialization can convert these complex objects into byte strings for such use. After the byte strings are transmitted, the receiver will have to recover the original object from the byte string. This is known as deserialization.

    Example you have an object

    {foo: [1, 4, 7, 10], bar: "baz"}
    serializing into JSON will convert it into a string:

    '{"foo":[1,4,7,10],"bar":"baz"}'
    which can be stored or sent through wire to anywhere. The receiver can then deserialize this string to get back the original object. {foo: [1, 4, 7, 10], bar: "baz"}

     

    Thanks

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos