Search in sources :

Example 1 with Stringifier

use of io.spine.string.Stringifier 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;
}
Also used : Type(java.lang.reflect.Type) Stringifier(io.spine.string.Stringifier) StringifierRegistry(io.spine.string.StringifierRegistry) TextFormat.shortDebugString(com.google.protobuf.TextFormat.shortDebugString)

Aggregations

TextFormat.shortDebugString (com.google.protobuf.TextFormat.shortDebugString)1 Stringifier (io.spine.string.Stringifier)1 StringifierRegistry (io.spine.string.StringifierRegistry)1 Type (java.lang.reflect.Type)1