Skip to content

Commit 2a67c42

Browse files
committed
Found a better way of handling extra keys without dealing with unsafe casts.
1 parent f6a2993 commit 2a67c42

2 files changed

Lines changed: 9 additions & 10 deletions

File tree

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
package io.github.hikingc.matrixsdk.api.well_known;
22

33
import com.fasterxml.jackson.annotation.JsonCreator;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
45

5-
import java.util.HashMap;
66
import java.util.Map;
77

8-
public record PolicyServerInformation(Map<String, Object> publicKeys, Map<String, Object> otherProperties) {
9-
/// Deserialization helper to accommodate additional unknown fields.
10-
///
11-
/// @param raw input key-values from a response.
12-
/// @return deserialized [PolicyServerInformation] with corresponding values.
8+
public record PolicyServerInformation(
9+
@JsonProperty(value = "public_keys", required = true) Map<String, String> publicKeys,
10+
Map<String, Object> extraFields) {
11+
1312
@JsonCreator
14-
public static PolicyServerInformation of(Map<String, Object> raw) {
15-
Map<String, Object> copy = new HashMap<>(raw);
16-
var room = (Map<String, Object>) copy.remove("public_keys");
17-
return new PolicyServerInformation(room, Map.copyOf(copy));
13+
public PolicyServerInformation(
14+
@JsonProperty(value = "public_keys", required = true) Map<String, String> publicKeys) {
15+
this(Map.copyOf(publicKeys), Map.of());
1816
}
1917
}

‎matrix-sdk-core/src/test/java/io/github/hikingc/matrixsdk/api/MatrixDiscoveryTest.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,6 @@ void getFetchPolicyServer_ReturnAnObject() {
9898
""")));
9999
var response = matrixDiscovery.fetchPolicyServer();
100100
assertThat(response).isNotNull();
101+
assertThat(response.publicKeys().get("ed25519")).contains("6yhHGKhCiXTSEN2ksjV7kX_N6rBQZ3Xb-M7LlC6NS-s");
101102
}
102103
}

0 commit comments

Comments
 (0)