How to serialize Object to JSON?

前端 未结 7 1697
面向向阳花
面向向阳花 2020-11-27 05:49

I need to serialize some objects to a JSON and send to a WebService. How can I do it using the org.json library? Or I\'ll have to use another one? Here is the class I need t

7条回答
  •  旧时难觅i
    2020-11-27 06:12

    One can use the Jackson library as well.

    Add Maven Dependency:

    
      com.fasterxml.jackson.core 
      jackson-core
    
    

    Simply do this:

    ObjectMapper mapper = new ObjectMapper();
    String json = mapper.writeValueAsString( serializableObject );
    

提交回复
热议问题