Advertisement
temirlan100

Untitled

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