Array of objects vs Object of Objects

后端 未结 6 1093
有刺的猬
有刺的猬 2020-12-13 05:56

The issue is to decided the trade offs between following notations:

JSON based:

\"users\": {
    \"id1\": {
        \"id\": \"id1\",         


        
6条回答
  •  一向
    一向 (楼主)
    2020-12-13 06:33

    Both approaches have their pros and cons and depends on what is it that you are looking at.

    The array approach is easy to serialize and is more 'framework' friendly (you can add beans to a list and serialize the list and you are done). This allows, for example, a web-container to return the response without requiring any customization. This is likely to be supported out-of-the-box by most frameworks.

    On the other hand, the object based approach is more difficult to generate (in relative terms) but its easier to lookup given the key is known.

    So for ease of implementation (by producer), go for the array based approach. For ease of use (consumed by clients) go for object based approach.

提交回复
热议问题