throws ContextSerializationException {
if(contextHolder.hasRawSerializedForm()) {
return contextHolder.getRawSerializedForm();
}
DirectionAwareContextSerializer serializer = contextHolder.getSerializer();
String data = contextHolder.hasSerialized()
? contextHolder.getSerialized()
: serializer.serialize(contextHolder.getContext(), direction);
if (null == data) {
throw new ContextSerializationException("Serializer returned null for context name: " + contextHolder.getContextName());
}
if (data.isEmpty()) {
data = maskEmptyString();
}
StringBuilder builder = new StringBuilder();
builder.append(SERIALIZATION_FORMAT_VER);
builder.append(CONTEXT_SERIALIZATION_PROPS_SEPARATOR);
builder.append(contextHolder.getSerializerClassName());
builder.append(CONTEXT_SERIALIZATION_PROPS_SEPARATOR);
builder.append(serializer.getVersion());
builder.append(CONTEXT_SERIALIZATION_PROPS_SEPARATOR);
builder.append(data);
return builder.toString();
}