Way to Consume Json request as Json object in Jersey Rest Service

后端 未结 3 680
离开以前
离开以前 2021-01-17 05:22

Hi I tried googling around but cannot find solution that I want to achieve.

Example to map json to java object we do

 @POST
 @Consumes(application/j         


        
相关标签:
3条回答
  • 2021-01-17 06:04

    If you are using the same configuration as web.xml setup gists for Jersey1 and Jackson2, then you may do as below. This is a possible alternative than using JSONObject

    @POST
    @Path("/sub_path2")
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    public Map<String,Object> saveMethod( Map<String,Object> params  ) throws IOException {
    
        // Processing steps
    
        return params;
    }
    
    0 讨论(0)
  • 2021-01-17 06:14

    It was a straight solution that I happened to overlooked... my bad. Jersey is way smarter than I thought... curious to know what magic happens under the layers

    @POST
     @Consumes(application/json)
     @Produces(application/json)
     public Response createUpdateDeleteManualClinicalData(JsonNode jsonNode) {
    //jsoNode body casted automatically into JsonNode
    }
    
    0 讨论(0)
  • 2021-01-17 06:22

    What is the web.xml configuration you are using? Is it something similar to here web.xml setup gists for Jersey1 and Jackson2?

    0 讨论(0)
提交回复
热议问题