use of org.jbpm.marshalling.impl.JBPMMessages.VariableContainer in project jbpm by kiegroup.
the class ContentMarshallerHelper method unmarshall.
public static Object unmarshall(byte[] content, Environment env, ClassLoader classloader) {
ProtobufMarshallerReaderContext context = null;
try {
ByteArrayInputStream stream = new ByteArrayInputStream(content);
MarshallingConfigurationImpl marshallingConfigurationImpl = null;
if (env != null) {
marshallingConfigurationImpl = new MarshallingConfigurationImpl((ObjectMarshallingStrategy[]) env.get(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES), false, false);
} else {
marshallingConfigurationImpl = new MarshallingConfigurationImpl(new ObjectMarshallingStrategy[] { new SerializablePlaceholderResolverStrategy(ClassObjectMarshallingStrategyAcceptor.DEFAULT) }, false, false);
}
ObjectMarshallingStrategyStore objectMarshallingStrategyStore = marshallingConfigurationImpl.getObjectMarshallingStrategyStore();
context = new ProtobufMarshallerReaderContext(stream, null, null, objectMarshallingStrategyStore, null, env);
if (classloader != null) {
context.setClassLoader(classloader);
} else {
context.setClassLoader(ContentMarshallerHelper.class.getClassLoader());
}
ExtensionRegistry registry = PersisterHelper.buildRegistry(context, null);
Header _header = PersisterHelper.readFromStreamWithHeaderPreloaded(context, registry);
try {
VariableContainer parseFrom = JBPMMessages.VariableContainer.parseFrom(_header.getPayload(), registry);
Map<String, Object> value = ProtobufProcessMarshaller.unmarshallVariableContainerValue(context, parseFrom);
// in case there was single variable stored return only that variable and not map
if (value.containsKey(SINGLE_VAR_KEY) && value.size() == 1) {
return value.get(SINGLE_VAR_KEY);
}
return value;
} catch (Exception e) {
// backward compatible fallback mechanism to ensure existing data can be read properly
return fallbackParse(context, _header, registry);
}
} catch (Exception ex) {
logger.warn("Exception while unmarshaling content", ex);
}
return null;
}
use of org.jbpm.marshalling.impl.JBPMMessages.VariableContainer in project jbpm by kiegroup.
the class ProtobufProcessMarshaller method marshallVariablesContainer.
public static VariableContainer marshallVariablesContainer(MarshallerWriteContext context, Map<String, Object> variables) throws IOException {
JBPMMessages.VariableContainer.Builder vcbuilder = JBPMMessages.VariableContainer.newBuilder();
for (String key : variables.keySet()) {
JBPMMessages.Variable.Builder builder = JBPMMessages.Variable.newBuilder().setName(key);
if (variables.get(key) != null) {
ObjectMarshallingStrategy strategy = context.getObjectMarshallingStrategyStore().getStrategyObject(variables.get(key));
Integer index = context.getStrategyIndex(strategy);
builder.setStrategyIndex(index).setValue(ByteString.copyFrom(strategy.marshal(context.getStrategyContext().get(strategy), (ObjectOutputStream) context, variables.get(key))));
}
vcbuilder.addVariable(builder.build());
}
return vcbuilder.build();
}
Aggregations