Advertisement
kp2016

Untitled

Oct 23rd, 2020
1,790
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.73 KB | None | 0 0
  1.   @Override
  2.   @NonNull
  3.   public ColumnAdapter<Map<Subject, String>, String> dataConverter() {
  4.     return new ColumnAdapter<Map<Subject, String>, String>() {
  5.       @Override
  6.       @NonNull
  7.       public String encode(@NonNull Map<Subject, String> model) {
  8.         if (model == null) return null;
  9.         Type type = new TypeToken<Map<Subject, String>>(){}.getType();
  10.         Gson gson = new Gson();
  11.         return gson.toJson(model, type);
  12.       }
  13.  
  14.       @Override
  15.       public Map<Subject, String> decode(String model) {
  16.         if (model == null) return null;
  17.         Type type = new TypeToken<Map<Subject, String>>(){}.getType();
  18.         Gson gson = new Gson();
  19.         return gson.fromJson(model, type);
  20.       }
  21.     };
  22.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement