From 9ac402eb004eaa46476cc9b2ee6de5fe85d03993 Mon Sep 17 00:00:00 2001 From: Oswald Quek Date: Mon, 9 Sep 2024 09:39:40 +0100 Subject: [PATCH] use nicer collect style --- .../adminusers/model/ServiceNamesDeserializer.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main/java/uk/gov/pay/adminusers/model/ServiceNamesDeserializer.java b/src/main/java/uk/gov/pay/adminusers/model/ServiceNamesDeserializer.java index d0c174639..e9b363a5b 100644 --- a/src/main/java/uk/gov/pay/adminusers/model/ServiceNamesDeserializer.java +++ b/src/main/java/uk/gov/pay/adminusers/model/ServiceNamesDeserializer.java @@ -7,17 +7,15 @@ import uk.gov.service.payments.commons.model.SupportedLanguage; import java.io.IOException; -import java.util.Collections; -import java.util.HashMap; import java.util.Map; +import static java.util.stream.Collectors.toUnmodifiableMap; + public class ServiceNamesDeserializer extends JsonDeserializer> { @Override public Map deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { - Map supportedLanguageToServiceName = new HashMap<>(); - jsonParser.getCodec().readValue(jsonParser, new TypeReference>() {}) - .forEach((key, value) -> - supportedLanguageToServiceName.put(SupportedLanguage.fromIso639AlphaTwoCode(key), value)); - return Collections.unmodifiableMap(supportedLanguageToServiceName); + return jsonParser.getCodec().readValue(jsonParser, new TypeReference>() {}) + .entrySet().stream() + .collect(toUnmodifiableMap(entry -> SupportedLanguage.fromIso639AlphaTwoCode(entry.getKey()), Map.Entry::getValue)); } }