+
+ public static class JsonSessionStoreDeserializer extends JsonDeserializer<JsonSessionStore> {
+
+ @Override
+ public JsonSessionStore deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
+ JsonNode node = jsonParser.getCodec().readTree(jsonParser);
+
+ Map<AxolotlAddress, byte[]> sessionMap = new HashMap<>();
+ if (node.isArray()) {
+ for (JsonNode session : node) {
+ String sessionName = session.get("name").asText();
+ try {
+ sessionMap.put(new AxolotlAddress(sessionName, session.get("deviceId").asInt()), Base64.decode(session.get("record").asText()));
+ } catch (IOException e) {
+ System.out.println(String.format("Error while decoding session for: %s", sessionName));
+ }
+ }
+ }
+
+ JsonSessionStore sessionStore = new JsonSessionStore();
+ sessionStore.addSessions(sessionMap);
+
+ return sessionStore;
+
+ }
+ }
+
+ public static class JsonPreKeyStoreSerializer extends JsonSerializer<JsonSessionStore> {
+
+ @Override
+ public void serialize(JsonSessionStore jsonSessionStore, JsonGenerator json, SerializerProvider serializerProvider) throws IOException, JsonProcessingException {
+ json.writeStartArray();
+ for (Map.Entry<AxolotlAddress, byte[]> preKey : jsonSessionStore.sessions.entrySet()) {
+ json.writeStartObject();
+ json.writeStringField("name", preKey.getKey().getName());
+ json.writeNumberField("deviceId", preKey.getKey().getDeviceId());
+ json.writeStringField("record", Base64.encodeBytes(preKey.getValue()));
+ json.writeEndObject();
+ }
+ json.writeEndArray();
+ }
+ }