How to convert HTTP Request Body into JSON Object in Java

后端 未结 6 928
挽巷
挽巷 2020-12-10 04:45

I am trying find a Java lib/api that will allow me to turn the contents of a HTTP Request POST body into a JSON object.

Ideally I would like to use a Apache Sling li

6条回答
  •  余生分开走
    2020-12-10 05:12

    I recommend trying Apache Commons Beanutils.

    ServeltRequest request;
    
    Map map = request.getParameterMap();
    MyObject object = new MyObject();
    BeanUtils.populate(object, map);
    String json = object.toJSON() //using any JSON library
    

提交回复
热议问题