From f62b50f5a14e03acb06a7dd04bc3ead45d40aac4 Mon Sep 17 00:00:00 2001 From: Alan Orth Date: Fri, 31 Jul 2020 21:52:48 +0300 Subject: [PATCH] Use the @SerializedName annotation for ISO 3166-1 Our Java class needs to match the input JSON structure exactly, but we can't use "3166-1" as a variable name so we tell GSON to use the name "3166-1" when deserializing to countries. --- .../java/org/cgiar/cgspace/ctasks/CountriesVocabulary.java | 3 ++- src/main/java/org/cgiar/cgspace/ctasks/CountryCodeTagger.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/cgiar/cgspace/ctasks/CountriesVocabulary.java b/src/main/java/org/cgiar/cgspace/ctasks/CountriesVocabulary.java index 4d830aa..4e9dd09 100644 --- a/src/main/java/org/cgiar/cgspace/ctasks/CountriesVocabulary.java +++ b/src/main/java/org/cgiar/cgspace/ctasks/CountriesVocabulary.java @@ -20,9 +20,10 @@ package org.cgiar.cgspace.ctasks; import javax.annotation.Nullable; import java.util.List; +import com.google.gson.annotations.SerializedName; public class CountriesVocabulary { - List countries; //required + @SerializedName("3166-1") List countries; //required class Country { private String name; //required diff --git a/src/main/java/org/cgiar/cgspace/ctasks/CountryCodeTagger.java b/src/main/java/org/cgiar/cgspace/ctasks/CountryCodeTagger.java index 5793ac0..7d8bd7b 100644 --- a/src/main/java/org/cgiar/cgspace/ctasks/CountryCodeTagger.java +++ b/src/main/java/org/cgiar/cgspace/ctasks/CountryCodeTagger.java @@ -82,7 +82,7 @@ public class CountryCodeTagger extends AbstractCurationTask System.out.println(isocodesCountriesJson.getClass()); System.out.println(cgspaceCountriesJson.getClass()); - for (CountriesVocabulary.Country country : cgspaceCountriesJson.countries) { + for (CountriesVocabulary.Country country : isocodesCountriesJson.countries) { System.out.println(country.getName()); }