X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/0744dcccf117064dcf6c8dbb1312565c0f3e15cb..d91e20e1f8a8626ce8e5d5f11535dc05f3c63f31:/src/main/java/org/asamk/signal/JsonContactsStore.java diff --git a/src/main/java/org/asamk/signal/JsonContactsStore.java b/src/main/java/org/asamk/signal/JsonContactsStore.java deleted file mode 100644 index 500684fe..00000000 --- a/src/main/java/org/asamk/signal/JsonContactsStore.java +++ /dev/null @@ -1,56 +0,0 @@ -package org.asamk.signal; - -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.*; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class JsonContactsStore { - @JsonProperty("contacts") - @JsonSerialize(using = JsonContactsStore.MapToListSerializer.class) - @JsonDeserialize(using = ContactsDeserializer.class) - private Map contacts = new HashMap<>(); - - private static final ObjectMapper jsonProcessor = new ObjectMapper(); - - void updateContact(ContactInfo contact) { - contacts.put(contact.number, contact); - } - - ContactInfo getContact(String number) { - return contacts.get(number); - } - - List getContacts() { - return new ArrayList<>(contacts.values()); - } - - public static class MapToListSerializer extends JsonSerializer> { - @Override - public void serialize(final Map value, final JsonGenerator jgen, final SerializerProvider provider) throws IOException { - jgen.writeObject(value.values()); - } - } - - public static class ContactsDeserializer extends JsonDeserializer> { - @Override - public Map deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { - Map contacts = new HashMap<>(); - JsonNode node = jsonParser.getCodec().readTree(jsonParser); - for (JsonNode n : node) { - ContactInfo c = jsonProcessor.treeToValue(n, ContactInfo.class); - contacts.put(c.number, c); - } - - return contacts; - } - } -}