Tenho as seguintes classes:
public class OnesignalRequestModel {
private String app_id;
private List<IDModelJson> include_player_ids;
private ContentJsonModel content;
public String getApp_id() {
return app_id;
}
public void setApp_id(String app_id) {
this.app_id = app_id;
}
public List<IDModelJson> getInclude_player_ids() {
return include_player_ids;
}
public void setInclude_player_ids(List<IDModelJson> include_player_ids) {
this.include_player_ids = include_player_ids;
}
public ContentJsonModel getContent() {
return content;
}
public void setContent(ContentJsonModel content) {
this.content = content;
}
}
public class IDModelJson {
private Integer id_onesignal;
public Integer getId_onesignal() {
return id_onesignal;
}
public void setId_onesignal(Integer id_onesignal) {
this.id_onesignal = id_onesignal;
}
}
class ContentJsonModel {
public String getEn() {
return en;
}
public void setEn(String en) {
this.en = en;
}
private String en;
}
E gostaria de montar um JSON nesse estilo (montei em Python com tanta facilidade...)
{"app_id": "app_id_do_usuario", "include_player_ids": [id_onesignal], "contents": {"en": mensagem}}
Mas não entendi como posso, efetivamente, montar ele usando o Jackson e aproveitando os modelos que escrevi.
A classe que quero implementar é essa aqui:
public class RequestOneSignal {
final ObjectMapper mapper = new ObjectMapper();
public int doPost() throws IOException {
HttpClient client = HttpClientBuilder.create().build();
try (CloseableHttpClient clientClose = HttpClients.createDefault()) {
HttpPost post = new HttpPost("url");
post.setHeader("Content-Type", "application/json; charset=utf-8");
}
}
private HttpEntity createEntity(List<Integer> clientsID){
//Aqui, quero gerar o JSON e poder setar numa entity para fazer o post
}
}