temirlan100

Untitled

Nov 14th, 2024
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.78 KB | None | 0 0
  1. import com.fasterxml.jackson.databind.ObjectMapper;
  2. import java.io.IOException;
  3.  
  4. public class Notification {
  5.     private String patientId;
  6.     private String message;
  7.     private Doctor assignedDoctor;
  8.     private String nextAppointmentDate;
  9.  
  10.     public Notification() {
  11.     }
  12.  
  13.     public Notification(String patientId, String message) {
  14.         this.patientId = patientId;
  15.         this.message = message;
  16.     }
  17.  
  18.     public String getPatientId() {
  19.         return patientId;
  20.     }
  21.  
  22.     public void setPatientId(String patientId) {
  23.         this.patientId = patientId;
  24.     }
  25.  
  26.     public String getMessage() {
  27.         return message;
  28.     }
  29.  
  30.     public void setMessage(String message) {
  31.         this.message = message;
  32.     }
  33.  
  34.     public Doctor getAssignedDoctor() {
  35.         return assignedDoctor;
  36.     }
  37.  
  38.     public void setAssignedDoctor(Doctor assignedDoctor) {
  39.         this.assignedDoctor = assignedDoctor;
  40.     }
  41.  
  42.     public String getNextAppointmentDate() {
  43.         return nextAppointmentDate;
  44.     }
  45.  
  46.     public void setNextAppointmentDate(String nextAppointmentDate) {
  47.         this.nextAppointmentDate = nextAppointmentDate;
  48.     }
  49.  
  50.     // Методы для сериализации и десериализации JSON
  51.     private static final ObjectMapper objectMapper = new ObjectMapper();
  52.  
  53.     public static Notification fromJson(String json) {
  54.         try {
  55.             return objectMapper.readValue(json, Notification.class);
  56.         } catch (IOException e) {
  57.             e.printStackTrace();
  58.             return null;
  59.         }
  60.     }
  61.  
  62.     public String toJson() {
  63.         try {
  64.             return objectMapper.writeValueAsString(this);
  65.         } catch (IOException e) {
  66.             e.printStackTrace();
  67.             return null;
  68.         }
  69.     }
  70. }
  71.  
Advertisement
Add Comment
Please, Sign In to add comment