How to convert POJO to JSON and vice versa?

前端 未结 6 751
忘了有多久
忘了有多久 2020-11-27 15:40

I want to know if there is any Java API available to convert a POJO object to a JSON object and vice versa.

6条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-27 16:20

    Use GSON for converting POJO to JSONObject. Refer here.

    For converting JSONObject to POJO, just call the setter method in the POJO and assign the values directly from the JSONObject.

提交回复
热议问题