mirror of
https://github.com/ilri/cgspace-java-helpers.git
synced 2024-12-23 13:34:38 +01:00
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.
This commit is contained in:
parent
968bd354fe
commit
f62b50f5a1
@ -20,9 +20,10 @@ package org.cgiar.cgspace.ctasks;
|
|||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
public class CountriesVocabulary {
|
public class CountriesVocabulary {
|
||||||
List<Country> countries; //required
|
@SerializedName("3166-1") List<Country> countries; //required
|
||||||
|
|
||||||
class Country {
|
class Country {
|
||||||
private String name; //required
|
private String name; //required
|
||||||
|
@ -82,7 +82,7 @@ public class CountryCodeTagger extends AbstractCurationTask
|
|||||||
System.out.println(isocodesCountriesJson.getClass());
|
System.out.println(isocodesCountriesJson.getClass());
|
||||||
System.out.println(cgspaceCountriesJson.getClass());
|
System.out.println(cgspaceCountriesJson.getClass());
|
||||||
|
|
||||||
for (CountriesVocabulary.Country country : cgspaceCountriesJson.countries) {
|
for (CountriesVocabulary.Country country : isocodesCountriesJson.countries) {
|
||||||
System.out.println(country.getName());
|
System.out.println(country.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user