I want to create a Post method for my controller for my Spring boot application, I have an Entity Alert, with the elements below, but I need to send a specific request format to my API, I tried using save() method but it doesn't work, does someone knows how to specify each element for the Json request? and also how to go to the next element when we use Serializable? Thank you so much for help
{
"deviceEUIs": [
"1122233344"
],
"alertModes": [
{
"type": "MOTION",
"notifyByEmail": true,
"notifyBySMS": true,
"notifyOnInterface": true
}
]
}
@Entity
@Table(name = "Alert")
public class Alert implements Serializable{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(generator = "uuid2")
@GenericGenerator(name = "uuid2", strategy = "uuid2")
@Column(columnDefinition = "BINARY(16)")
private UUID alertRef;
@OneToMany(mappedBy = "alert", cascade = CascadeType.ALL)
private Set<AlertModes> alertModes;
@ManyToMany(cascade = CascadeType.ALL)
@JoinTable
private Set<Subscriber> subscribers;
@ManyToMany(mappedBy = "alerts")
private Set<Device> devices;
@Column(name = "last_update", columnDefinition = "DATETIME", nullable = false)
@Temporal(TemporalType.TIMESTAMP)
private Date lastUpdate;
And for my controller:
@RestController
@RequestMapping("/api/alerts")
public class AlertsController extends AbstractController{
@Autowired
private AlertRepository alertRepository;
@PostMapping()
public void createAlert(@RequestBody Alert alert) {
alertRepository.save(alert);
}
}