Deserialize null capabilities in `Device` entities as empty sets
This commit is contained in:
parent
fc0a7b7657
commit
c9a396b9e3
|
@ -6,6 +6,7 @@ package org.whispersystems.textsecuregcm.storage;
|
||||||
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonSetter;
|
||||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
|
@ -178,6 +179,7 @@ public class Device {
|
||||||
return capabilities;
|
return capabilities;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JsonSetter
|
||||||
public void setCapabilities(@Nullable final Set<DeviceCapability> capabilities) {
|
public void setCapabilities(@Nullable final Set<DeviceCapability> capabilities) {
|
||||||
this.capabilities = (capabilities == null || capabilities.isEmpty())
|
this.capabilities = (capabilities == null || capabilities.isEmpty())
|
||||||
? Collections.emptySet()
|
? Collections.emptySet()
|
||||||
|
|
|
@ -6,11 +6,15 @@
|
||||||
package org.whispersystems.textsecuregcm.storage;
|
package org.whispersystems.textsecuregcm.storage;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
import org.junit.jupiter.params.provider.CsvSource;
|
import org.junit.jupiter.params.provider.CsvSource;
|
||||||
|
import org.whispersystems.textsecuregcm.util.SystemMapper;
|
||||||
|
|
||||||
class DeviceTest {
|
class DeviceTest {
|
||||||
|
|
||||||
|
@ -42,4 +46,25 @@ class DeviceTest {
|
||||||
assertEquals(expectExpired, device.isExpired());
|
assertEquals(expectExpired, device.isExpired());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void deserializeCapabilities() throws JsonProcessingException {
|
||||||
|
{
|
||||||
|
final Device device = SystemMapper.jsonMapper().readValue("""
|
||||||
|
{
|
||||||
|
"capabilities": null
|
||||||
|
}
|
||||||
|
""", Device.class);
|
||||||
|
|
||||||
|
assertNotNull(device.getCapabilities(),
|
||||||
|
"Device deserialization should populate null capabilities with an empty set");
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
final Device device = SystemMapper.jsonMapper().readValue("{}", Device.class);
|
||||||
|
|
||||||
|
assertNotNull(device.getCapabilities(),
|
||||||
|
"Device deserialization should populate null capabilities with an empty set");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue