本文整理了Java中org.camunda.bpm.engine.variable.Variables.serializedObjectValue()
方法的一些代码示例,展示了Variables.serializedObjectValue()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Variables.serializedObjectValue()
方法的具体详情如下:
包路径:org.camunda.bpm.engine.variable.Variables
类名称:Variables
方法名:serializedObjectValue
[英]Returns a builder to create a new ObjectValue from a serialized object representation.
[中]返回一个生成器,以从序列化对象表示创建新的ObjectValue。
代码示例来源:origin: camunda/camunda-bpm-platform
/**
* Shortcut for {@code Variables.serializedObjectValue().serializedValue(value)}
*/
public static SerializedObjectValueBuilder serializedObjectValue(String value) {
return serializedObjectValue().serializedValue(value);
}
代码示例来源:origin: camunda/camunda-bpm-platform
public static SerializedObjectValueBuilder createSerializedMap(){
return serializedObjectValue("{\"foo\": \"bar\"}").serializationDataFormat("application/json").objectTypeName(HashMap.class.getName());
}
}
代码示例来源:origin: camunda/camunda-bpm-platform
public static SerializedObjectValueBuilder createSerializedMap(){
return serializedObjectValue("{\"foo\": \"bar\"}").serializationDataFormat("application/json").objectTypeName(HashMap.class.getName());
}
代码示例来源:origin: camunda/camunda-bpm-platform
/**
* Shortcut for {@code Variables.serializedObjectValue().serializedValue(value).setTransient(isTransient)}
*/
public static SerializedObjectValueBuilder serializedObjectValue(String value, boolean isTransient) {
return (SerializedObjectValueBuilder) serializedObjectValue().serializedValue(value).setTransient(isTransient);
}
代码示例来源:origin: camunda/camunda-bpm-platform
public SerializableValue createValueFromSerialized(String serializedValue, Map<String, Object> valueInfo) {
SerializedObjectValueBuilder builder = Variables.serializedObjectValue(serializedValue);
if(valueInfo != null) {
applyValueInfo(builder, valueInfo);
}
return builder.create();
}
代码示例来源:origin: camunda/camunda-bpm-platform
@Test
public void testJacksonBug146AsVariable() {
InputStream resourceAsStream = getClass().getClassLoader().getResourceAsStream("org/camunda/bpm/integrationtest/functional/spin/jackson146.json");
String jackson146 = SpinIoUtil.inputStreamAsString(resourceAsStream);
ProcessInstance pi = runtimeService.startProcessInstanceByKey("testProcess", Variables.createVariables()
.putValue("jackson146", serializedObjectValue(jackson146).serializationDataFormat("application/json").objectTypeName(HashMap.class.getName())));
// file has 4000 characters in length a
// 20 characters per repeated JSON object
ObjectValue objectValue = runtimeService.getVariableTyped(pi.getId(), "jackson146", true);
HashMap<String, List<Object>> map = (HashMap<String, List<Object>>) objectValue.getValue();
assertEquals(200, map.get("abcdef").size());
}
代码示例来源:origin: camunda/camunda-bpm-platform
public static VariableMap createMockSerializedVariables() {
VariableMap variables = Variables.createVariables();
ObjectValue serializedVar = Variables.serializedObjectValue(EXAMPLE_VARIABLE_INSTANCE_SERIALIZED_VALUE)
.serializationDataFormat(FORMAT_APPLICATION_JSON)
.objectTypeName(ArrayList.class.getName())
.create();
ObjectValue deserializedVar = new ObjectValueImpl(EXAMPLE_VARIABLE_INSTANCE_DESERIALIZED_VALUE,
EXAMPLE_VARIABLE_INSTANCE_SERIALIZED_VALUE,
FORMAT_APPLICATION_JSON, Object.class.getName(), true);
variables.putValueTyped(EXAMPLE_VARIABLE_INSTANCE_NAME, serializedVar);
variables.putValueTyped(EXAMPLE_DESERIALIZED_VARIABLE_INSTANCE_NAME, deserializedVar);
return variables;
}
代码示例来源:origin: camunda/camunda-bpm-platform
@Test
public void spinCanBeUsedForVariableSerialization() {
ProcessInstance pi = runtimeService.startProcessInstanceByKey("testProcess", Variables.createVariables()
.putValue("serializedObject", serializedObjectValue("{\"foo\": \"bar\"}").serializationDataFormat("application/json").objectTypeName(HashMap.class.getName())));
ObjectValue objectValue = runtimeService.getVariableTyped(pi.getId(), "serializedObject", true);
HashMap<String, String> expected = new HashMap<String, String>();
expected.put("foo", "bar");
Assert.assertEquals(expected, objectValue.getValue());
}
代码示例来源:origin: camunda/camunda-bpm-platform
@Test
@Deployment(resources = ONE_TASK_PROCESS)
public void testSetJavaObjectSerializedEmptySerializationDataFormat() throws Exception {
ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
JavaSerializable javaSerializable = new JavaSerializable("foo");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
new ObjectOutputStream(baos).writeObject(javaSerializable);
String serializedObject = StringUtil.fromBytes(Base64.encodeBase64(baos.toByteArray()), engineRule.getProcessEngine());
thrown.expect(ProcessEngineException.class);
thrown.expectMessage("Cannot set variable with name simpleBean. Java serialization format is prohibited");
runtimeService.setVariable(instance.getId(), "simpleBean",
serializedObjectValue(serializedObject)
.objectTypeName(JavaSerializable.class.getName())
.create());
}
代码示例来源:origin: camunda/camunda-bpm-platform
@Test
@Deployment
public void testJavaObjectDeserializedInFirstCommand() throws Exception {
// this test makes sure that if a serialized value is set, it can be deserialized in the same command in which it is set.
// given
// a serialized Java Object
JavaSerializable javaSerializable = new JavaSerializable("foo");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
new ObjectOutputStream(baos).writeObject(javaSerializable);
String serializedObject = StringUtil.fromBytes(Base64.encodeBase64(baos.toByteArray()), engineRule.getProcessEngine());
// if
// I start a process instance in which a Java Delegate reads the value in its deserialized form
runtimeService.startProcessInstanceByKey("oneTaskProcess", Variables.createVariables()
.putValue("varName", serializedObjectValue(serializedObject)
.serializationDataFormat(JAVA_DATA_FORMAT)
.objectTypeName(JavaSerializable.class.getName())
.create()));
// then
// it does not fail
}
代码示例来源:origin: camunda/camunda-bpm-platform
@Deployment(resources = ONE_TASK_PROCESS)
public void testFailSerializationForUnknownSerializedValueType() throws IOException {
// given
JavaSerializable pojo = new JavaSerializable("foo");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
new ObjectOutputStream(baos).writeObject(pojo);
String serializedObject = StringUtil.fromBytes(Base64.encodeBase64(baos.toByteArray()), processEngine);
ObjectValue serializedObjectValue = Variables
.serializedObjectValue(serializedObject)
.serializationDataFormat(SerializationDataFormats.JAVA)
.objectTypeName(pojo.getClass().getName())
.create();
VariableMap variables = Variables.createVariables().putValueTyped("var", serializedObjectValue);
// when
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", variables);
// then
JavaSerializable returnedPojo = (JavaSerializable) runtimeService.getVariable(processInstance.getId(), "var");
assertEquals(pojo, returnedPojo);
}
代码示例来源:origin: camunda/camunda-bpm-platform
@Test
@Deployment(resources = ONE_TASK_PROCESS)
public void testSetJavaObjectSerialized() throws Exception {
ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
JavaSerializable javaSerializable = new JavaSerializable("foo");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
new ObjectOutputStream(baos).writeObject(javaSerializable);
String serializedObject = StringUtil.fromBytes(Base64.encodeBase64(baos.toByteArray()), engineRule.getProcessEngine());
thrown.expect(ProcessEngineException.class);
thrown.expectMessage("Cannot set variable with name simpleBean. Java serialization format is prohibited");
runtimeService.setVariable(instance.getId(), "simpleBean",
serializedObjectValue(serializedObject)
.serializationDataFormat(JAVA_DATA_FORMAT)
.objectTypeName(JavaSerializable.class.getName())
.create());
}
代码示例来源:origin: camunda/camunda-bpm-platform
@Test
@Deployment(resources = ONE_TASK_PROCESS)
public void testSetJavaObjectSerialized() throws Exception {
ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
JavaSerializable javaSerializable = new JavaSerializable("foo");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
new ObjectOutputStream(baos).writeObject(javaSerializable);
String serializedObject = StringUtil.fromBytes(Base64.encodeBase64(baos.toByteArray()), engineRule.getProcessEngine());
runtimeService.setVariable(instance.getId(), "simpleBean",
serializedObjectValue(serializedObject)
.serializationDataFormat(JAVA_DATA_FORMAT)
.objectTypeName(JavaSerializable.class.getName())
.create());
// validate untyped value
JavaSerializable value = (JavaSerializable) runtimeService.getVariable(instance.getId(), "simpleBean");
assertEquals(javaSerializable, value);
// validate typed value
ObjectValue typedValue = runtimeService.getVariableTyped(instance.getId(), "simpleBean");
assertObjectValueDeserialized(typedValue, javaSerializable);
assertObjectValueSerializedJava(typedValue, javaSerializable);
}
代码示例来源:origin: camunda/camunda-bpm-platform
@Test
@OperateOnDeployment("client-app")
public void testDeserialization() {
String serializedValue = "<?xml version=\"1.0\" encoding=\"utf-8\"?><xmlserializable><property>value</property></xmlserializable>";
runtimeService.startProcessInstanceByKey("testProcess",
createVariables()
.putValueTyped("xmlSerializable",
serializedObjectValue(serializedValue)
.serializationDataFormat(SerializationDataFormats.XML)
.objectTypeName("org.camunda.bpm.integrationtest.functional.spin.XmlSerializable")
.create()));
}
代码示例来源:origin: camunda/camunda-bpm-platform
@Test
@OperateOnDeployment("dummy-client")
public void testGracefulDegradationOnMissingClassSpinXml() {
// given
Map<String, Object> variables = Variables.createVariables().putValue(
"priorityBean",
Variables.serializedObjectValue("<?xml version=\"1.0\" encoding=\"utf-8\"?><prioritybean></prioritybean>")
.serializationDataFormat(SerializationDataFormats.XML)
.objectTypeName(VARIABLE_CLASS_NAME)
.create());
// when
processInstance = runtimeService.startProcessInstanceByKey("priorityProcess", variables);
// then the job was created successfully and has the default priority although
// the bean could not be resolved due to a missing class
Job job = managementService.createJobQuery().singleResult();
Assert.assertEquals(DefaultJobPriorityProvider.DEFAULT_PRIORITY_ON_RESOLUTION_FAILURE, job.getPriority());
}
代码示例来源:origin: camunda/camunda-bpm-platform
@Test
@OperateOnDeployment("dummy-client")
public void testGracefulDegradationOnMissingClassSpinJson() {
// given
Map<String, Object> variables = Variables.createVariables().putValue(
"priorityBean",
Variables.serializedObjectValue("{}")
.serializationDataFormat(SerializationDataFormats.JSON)
.objectTypeName(VARIABLE_CLASS_NAME)
.create());
// when
processInstance = runtimeService.startProcessInstanceByKey("priorityProcess", variables);
// then the job was created successfully and has the default priority although
// the bean could not be resolved due to a missing class
Job job = managementService.createJobQuery().singleResult();
Assert.assertEquals(DefaultJobPriorityProvider.DEFAULT_PRIORITY_ON_RESOLUTION_FAILURE, job.getPriority());
}
代码示例来源:origin: camunda/camunda-bpm-platform
@Test
public void testStandaloneTaskTransientVariableSerializedObject() {
Task task = taskService.newTask();
task.setName("gonzoTask");
taskService.saveTask(task);
String taskId = task.getId();
try {
thrown.expect(ProcessEngineException.class);
thrown.expectMessage("Cannot set variable with name instrument. Java serialization format is prohibited");
taskService.setVariable(taskId, "instrument",
Variables.serializedObjectValue("any value")
.serializationDataFormat(Variables.SerializationDataFormats.JAVA)
.setTransient(true)
.create());
} finally {
taskService.deleteTask(taskId, true);
}
}
代码示例来源:origin: camunda/camunda-bpm-platform
@Deployment(resources={"org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn"})
@Test
public void testSubmitTaskFormForCmmnHumanTask() {
caseService.createCaseInstanceByKey("oneTaskCase");
Task task = taskService.createTaskQuery().singleResult();
String stringValue = "some string";
String serializedValue = "some value";
formService.submitTaskForm(task.getId(), createVariables()
.putValueTyped("boolean", booleanValue(null))
.putValueTyped("string", stringValue(stringValue))
.putValueTyped("serializedObject", serializedObjectValue(serializedValue)
.objectTypeName(String.class.getName())
.serializationDataFormat(Variables.SerializationDataFormats.JAVA)
.create())
.putValueTyped("object", objectValue(serializedValue).create()));
}
代码示例来源:origin: camunda/camunda-bpm-platform
@Test
@Deployment(resources = ONE_TASK_PROCESS)
public void testSetJavaObjectNullSerialized() throws Exception {
ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
// set null value as "serialized" object
runtimeService.setVariable(instance.getId(), "nullObject",
serializedObjectValue()
.serializationDataFormat(JAVA_DATA_FORMAT)
.create()); // Note: no object type name provided
// get null value via untyped api
assertNull(runtimeService.getVariable(instance.getId(), "nullObject"));
// get null via typed api
ObjectValue deserializedTypedValue = runtimeService.getVariableTyped(instance.getId(), "nullObject");
assertObjectValueDeserializedNull(deserializedTypedValue);
ObjectValue serializedTypedValue = runtimeService.getVariableTyped(instance.getId(), "nullObject", false);
assertObjectValueSerializedNull(serializedTypedValue);
}
代码示例来源:origin: camunda/camunda-bpm-platform
@Deployment(resources = {"org/camunda/bpm/engine/test/api/form/FormsProcess.bpmn20.xml"})
@Test
public void testSubmitStartFormDataTypedVariables() {
String procDefId = repositoryService.createProcessDefinitionQuery().singleResult().getId();
String stringValue = "some string";
String serializedValue = "some value";
ProcessInstance processInstance = formService.submitStartForm(procDefId,
createVariables()
.putValueTyped("boolean", booleanValue(null))
.putValueTyped("string", stringValue(stringValue))
.putValueTyped("serializedObject", serializedObjectValue(serializedValue)
.objectTypeName(String.class.getName())
.serializationDataFormat(Variables.SerializationDataFormats.JAVA)
.create())
.putValueTyped("object", objectValue(serializedValue).create()));
VariableMap variables = runtimeService.getVariablesTyped(processInstance.getId(), false);
assertEquals(booleanValue(null), variables.getValueTyped("boolean"));
assertEquals(stringValue(stringValue), variables.getValueTyped("string"));
assertNotNull(variables.<ObjectValue>getValueTyped("serializedObject").getValueSerialized());
assertNotNull(variables.<ObjectValue>getValueTyped("object").getValueSerialized());
}
内容来源于网络,如有侵权,请联系作者删除!