I have used the backticks syntax in order to generate some Java code with Javascript:
${body ? `con.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.writeBytes(${JSON.stringify(body)});
wr.flush();
wr.close();` : ``}
int responseCode = con.getResponseCode();
However, when body is null, the generated code contains 3-4 empty lines and then the "int responseCode .." line. I have tried extracting the part where body is true into a separate constant or moving the `` as first in the statement and none of them works. Any suggestions?
Thanks in advance!