Creating a json object using jackson

前端 未结 4 1993
孤城傲影
孤城傲影 2020-12-05 13:26

How can I create a json array like the example below using jackson.

I tried using ObjectMapper, but this does not seem correct.

      try (Director         


        
4条回答
  •  孤城傲影
    2020-12-05 13:44

    You can write an object to a json string. So I hope you have your data in an object of a class defined as per your need. Here is how you can convert that object into a json string:

    //1. Convert Java object to JSON format
    ObjectMapper mapper = new ObjectMapper();
    
    String jsonString = mapper.writeValueAsString(yourObject);
    

    See here for the full jackson-databind javadoc.

提交回复
热议问题