1 package org
.asamk
.signal
.manager
.storage
;
3 import com
.fasterxml
.jackson
.annotation
.JsonAutoDetect
;
4 import com
.fasterxml
.jackson
.annotation
.PropertyAccessor
;
5 import com
.fasterxml
.jackson
.core
.JsonGenerator
;
6 import com
.fasterxml
.jackson
.core
.JsonParser
;
7 import com
.fasterxml
.jackson
.databind
.DeserializationFeature
;
8 import com
.fasterxml
.jackson
.databind
.JsonNode
;
9 import com
.fasterxml
.jackson
.databind
.ObjectMapper
;
10 import com
.fasterxml
.jackson
.databind
.SerializationFeature
;
12 import org
.asamk
.signal
.manager
.storage
.recipients
.RecipientAddress
;
13 import org
.whispersystems
.signalservice
.api
.util
.UuidUtil
;
15 import java
.io
.InvalidObjectException
;
16 import java
.util
.Optional
;
23 public static ObjectMapper
createStorageObjectMapper() {
24 final ObjectMapper objectMapper
= new ObjectMapper();
26 objectMapper
.setVisibility(PropertyAccessor
.ALL
, JsonAutoDetect
.Visibility
.PUBLIC_ONLY
);
27 objectMapper
.enable(SerializationFeature
.INDENT_OUTPUT
); // for pretty print
28 objectMapper
.disable(DeserializationFeature
.FAIL_ON_UNKNOWN_PROPERTIES
);
29 objectMapper
.disable(JsonParser
.Feature
.AUTO_CLOSE_SOURCE
);
30 objectMapper
.disable(JsonGenerator
.Feature
.AUTO_CLOSE_TARGET
);
35 public static JsonNode
getNotNullNode(JsonNode parent
, String name
) throws InvalidObjectException
{
36 var node
= parent
.get(name
);
37 if (node
== null || node
.isNull()) {
38 throw new InvalidObjectException(String
.format("Incorrect file format: expected parameter %s not found ",
45 public static RecipientAddress
getRecipientAddressFromIdentifier(final String identifier
) {
46 if (UuidUtil
.isUuid(identifier
)) {
47 return new RecipientAddress(UuidUtil
.parseOrThrow(identifier
));
49 return new RecipientAddress(Optional
.empty(), Optional
.of(identifier
));