Put/get byte array value using JSONObject

前端 未结 4 931
孤街浪徒
孤街浪徒 2021-01-13 17:03

I tried to get my byte[] value from JSONObject using following code but I am not getting original byte[] value.

JSONAr         


        
4条回答
  •  太阳男子
    2021-01-13 17:50

    For tests example(com.fasterxml.jackson used):

            byte[] bytes = "pdf_report".getBytes("UTF-8");
            Mockito.when(reportService.createPackageInvoice(Mockito.any(String.class))).thenReturn(bytes);
            String jStr = new ObjectMapper().writeValueAsString(bytes).replaceAll("\\\"", ""); // return string with a '\"' escape...
            mockMvc.perform(get("/api/getReport").param("someparam", "222"))
                    .andExpect(status().isOk())
                    .andExpect(content().contentType(APPLICATION_JSON_UTF8))
                    ...
                    .andExpect(jsonPath("$.content", is(jStr)))
            ;
    

提交回复
热议问题