Skip to content

Commit

Permalink
use nicer collect style
Browse files Browse the repository at this point in the history
  • Loading branch information
oswaldquek committed Sep 9, 2024
1 parent c8e53c2 commit 9ac402e
Showing 1 changed file with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Map<SupportedLanguage, String>> {
@Override
public Map<SupportedLanguage, String> deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
Map<SupportedLanguage, String> supportedLanguageToServiceName = new HashMap<>();
jsonParser.getCodec().readValue(jsonParser, new TypeReference<Map<String, String>>() {})
.forEach((key, value) ->
supportedLanguageToServiceName.put(SupportedLanguage.fromIso639AlphaTwoCode(key), value));
return Collections.unmodifiableMap(supportedLanguageToServiceName);
return jsonParser.getCodec().readValue(jsonParser, new TypeReference<Map<String, String>>() {})
.entrySet().stream()
.collect(toUnmodifiableMap(entry -> SupportedLanguage.fromIso639AlphaTwoCode(entry.getKey()), Map.Entry::getValue));
}
}

0 comments on commit 9ac402e

Please sign in to comment.