-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(cherry picked from commit cdce1bb)
- Loading branch information
Showing
2 changed files
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
registry-ws/src/main/java/org/gbif/registry/ws/converter/CountryMessageConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.gbif.registry.ws.converter; | ||
|
||
import org.gbif.api.util.VocabularyUtils; | ||
import org.gbif.api.vocabulary.Country; | ||
import org.springframework.core.convert.converter.Converter; | ||
|
||
public class CountryMessageConverter implements Converter<String, Country> { | ||
|
||
@Override | ||
public Country convert(String source) { | ||
return parseCountry(source); | ||
} | ||
|
||
private Country parseCountry(String param) { | ||
Country country = Country.fromIsoCode(param); | ||
if (country == null) { | ||
// if nothing found also try by enum name | ||
country = VocabularyUtils.lookupEnum(param, Country.class); | ||
} | ||
return country; | ||
} | ||
} |