Skip to content

Commit

Permalink
More leniency, related to language codes.
Browse files Browse the repository at this point in the history
  • Loading branch information
mihxil committed Oct 6, 2024
1 parent ba0609a commit 9c7d46b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions media-berlijn/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
<groupId>nl.vpro.media</groupId>
<artifactId>media-domain</artifactId>
</dependency>
<dependency>
<groupId>org.meeuw.i18n</groupId>
<artifactId>i18n-iso-639</artifactId>
<version>3.4</version>
</dependency>
<dependency>
<groupId>nl.vpro.media</groupId>
<artifactId>media-classification</artifactId>
Expand Down
10 changes: 9 additions & 1 deletion media-berlijn/src/main/java/nl/vpro/berlijn/domain/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import jakarta.inject.Singleton;

import org.meeuw.i18n.languages.ISO_639;
import org.meeuw.i18n.languages.LanguageCode;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -77,17 +78,24 @@ public void setLenient(boolean lenient) {

// For some reason Whatson simply does not conform to standard.
private static final Map<String, LanguageCode> FALLBACKS = Map.of(
"XX", languageCode("zxx") // SEE https://publiekeomroep.atlassian.net/browse/VPPM-2238
"XX", languageCode("zxx"),
"ZZ", LanguageCode.UNKNOWN
// SEE https://publiekeomroep.atlassian.net/browse/VPPM-2238
///"", languageCode(null)
);

@SneakyThrows
public ProductMetadata parseProductMetadata(byte[] json) {
try {
LanguageCode.setFallbacks(FALLBACKS);
if (!mapper.isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)) {
ISO_639.setIgnoreNotFound();
}
return mapper.readValue(json, ProductMetadata.class);
} finally {
LanguageCode.resetFallBacks();
ISO_639.removeIgnoreNotFound();

}
}

Expand Down

0 comments on commit 9c7d46b

Please sign in to comment.