use of io.spine.string.StringifierRegistry in project core-java by SpineEventEngine.
the class Identifiers method idMessageToString.
// OK to cast to String as output type of Stringifier.
@SuppressWarnings("unchecked")
static String idMessageToString(Message message) {
checkNotNull(message);
final String result;
final StringifierRegistry registry = StringifierRegistry.getInstance();
final Class<? extends Message> msgClass = message.getClass();
final TypeToken<? extends Message> msgToken = TypeToken.of(msgClass);
final Type msgType = msgToken.getType();
final Optional<Stringifier<Object>> optional = registry.get(msgType);
if (optional.isPresent()) {
final Stringifier converter = optional.get();
result = (String) converter.convert(message);
} else {
result = convert(message);
}
return result;
}
Aggregations