Last active
January 18, 2023 13:09
-
-
Save mariuszs/4ae5f8a88351930e47635921ca9b6f41 to your computer and use it in GitHub Desktop.
FriendlyIdConverterProvider for Dropwizard
This file contains hidden or 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
@Provider | |
public class FriendlyIdConverterProvider implements ParamConverterProvider { | |
@Override | |
public <T> ParamConverter<T> getConverter(Class<T> clazz, Type type, Annotation[] annotations) { | |
if (clazz.getName().equals(UUID.class.getName())) { | |
return new ParamConverter<T>() { | |
@SuppressWarnings("unchecked") | |
@Override | |
public T fromString(String value) { | |
UUID uuid = FriendlyId.toUuid(value); | |
return (T) uuid; | |
} | |
@Override | |
public String toString(T bean) { | |
return FriendlyId.toFriendlyId((UUID) bean); | |
} | |
}; | |
} | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sounds sensible