1

What are the benefits of using ByteArrayOutputStream to convert the XML or JSON data to send over web socket instead of sending these values as Strings?

1

1 Answer 1

2
  1. Security: JSON and XML easy to decode.(mostly for WS / compare to WSS)

  2. Efficiency: In traffic usage and in most case encode/decode processing. Byte-Arrays could be very compact compare to string, specially with data that are not string by nature (compare 4-bytes Boolean array of size 32 with over 128 (32*4) byte need for string representation, both data usage and encode/decode CPU usage). check THIS link

  3. Generality: Sending all type of data including any objects with complex hierarchical inheritances between them. In order to decode JSON with complex Tree-Like inheritance, you need very complex parsing method.

  4. Simplicity: Enable to chunk data meaningfully. suppose we always use first 2 byte of data as it's type. (to decode the rest). Normally additional libraries do that for us.

  5. Integrity: Easily recognizing corrupted data. Even without checksum, 1-bit data-corruption could be detected in most case.

  6. Compatibility: Using serialized object with version to control compatibility. (version control)-Although you could add version in JSON, it could cause many difficulty, inefficiency and trouble. check THIS

And probably other reasons in special cases.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.