How to send enclose data in DELETE request in Jersey client?

Based on the code in Jersey 2.18 version, The class JerseyInvocation use a predefined HashMap to validate HTTP method and its Entity as below:

map.put("DELETE", EntityPresence.MUST_BE_NULL);
map.put("GET", EntityPresence.MUST_BE_NULL);
...

That's why we got this error "Entity must be null for http method DELETE".

While, please note that it also provide a Jersey client configuration property ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION to determine whether to stop the rest execution or not, so here we can use this property to suppress validation in order to continue to send a DELETE request with Entity. e.g.

    ClientConfig config = new ClientConfig();
    config.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
    Client client = ClientBuilder.newClient(config);
    ...

Just to note: if you use resteasy implementation of JAX RS Client API, you may use build().invoke():

client.target("$baseUrl$restEndPoint/$entityId")
                .request("application/json")
                .build("DELETE", Entity.entity(entity, MediaType.APPLICATION_JSON))
                .invoke()

But it does not work with jersey