jmsdk
jmsdk copied to clipboard
ObjectMapper configuration for json serialization
https://github.com/ma1uta/jmsdk/blob/f159926598b4f48060c3495b431a1a863bfa2866/jackson-support/src/main/java/io/github/ma1uta/matrix/support/jackson/DefaultObjectMapperProvider.java#L41
I replace mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
with mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
I use my own http client with the mapper and the jeon model class
and with /_matrix/client/r0/keys/query
, i had a bad request with NON_EMPTY because the serialization removes my empty list:
The Java object:
QueryRequest keysQuery = new QueryRequest(); keysQuery.setTimeout(5000L); Map<String, List<String>> devicesKeysRequest = new HashMap<>(); devicesKeysRequest.put(bobLogin.getUserId(), Collections.emptyList()); keysQuery.setDeviceKeys(devicesKeysRequest);
Serialized Json with NON_EMPTY => bad request:
{"timeout":5000}
Serialized Json with NON_NULL => good request:
{"timeout":5000,"device_keys":{"@a66bf63f-d9bc-41d1-99ce-467c2af61c26:matrix.docker.localhost":[]}}
In Matrix spec for /_matrix/client/r0/keys/query
:
device_keys : {string: [string]} | Required. The keys to be downloaded. A map from user ID, to a list of device IDs, or to an empty list to indicate all devices for the corresponding user.