Package org.jbpm.process.workitem.parser
Class ParserWorkItemHandler
- java.lang.Object
-
- org.jbpm.process.workitem.core.AbstractLogOrThrowWorkItemHandler
-
- org.jbpm.process.workitem.parser.ParserWorkItemHandler
-
- All Implemented Interfaces:
org.kie.api.runtime.process.WorkItemHandler
@Wid(widfile="ParserDefinitions.wid",name="Parser",displayName="Parser",defaultHandler="mvel: new org.jbpm.process.workitem.parser.ParserWorkItemHandler()",documentation="parser-workitem/index.html",category="parser-workitem",icon="Parser.png",parameters={@WidParameter(name="Format",required=true),@WidParameter(name="Type"),@WidParameter(name="Input")},results=@WidResult(name="Result",runtimeType="java.lang.Object"),mavenDepends=@WidMavenDepends(group="org.jbpm.contrib",artifact="parser-workitem",version="7.66.0.Final"),serviceInfo=@WidService(category="Parser",description="Parse Strings to objects and vice-versa",keywords="parse,java,object,string,xml,json",action=@WidAction(title="Parse Java object to string and vice-versa"),authinfo=@WidAuth)) public class ParserWorkItemHandler extends org.jbpm.process.workitem.core.AbstractLogOrThrowWorkItemHandlerWorkItemHandler that is capable of parsing String to objects and vice-versa. Currently supports only two formats- XML
- JSON
- Input - The input data. If you provide a string, the parser will try to parse the string to an object of type Type and format Format (see below), if not, it will try to parse the object to a String of format Format. It is a required parameter;
- Format - It is a required parameter that can have the values JSON or XML;
- Result - The result is an output parameter that will be a string if you provide an Input object that is not of String type; and an object of type Type if you provide an Input object of type String.
- Type - The FQN of the object type (for example com.acme.Customer)
Providing these parameters correctly is enough to use the parser task. Please bear in mind that it uses JAXB to parse the object, so it must have the @XmlRootElement annotation.
-
-
Field Summary
Fields Modifier and Type Field Description static StringFORMATOnly supports JSON or XML.static StringINPUTThe input object of type TYPE or String (if you set toObject)static StringJSONstatic StringRESULTThe resulting object or String (if toObject is false it will be a String).static StringTYPEThe target object type full qualified name (com.acme.Customer)static StringXML
-
Constructor Summary
Constructors Constructor Description ParserWorkItemHandler()ParserWorkItemHandler(ClassLoader cl)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidabortWorkItem(org.kie.api.runtime.process.WorkItem wi, org.kie.api.runtime.process.WorkItemManager wim)protected ObjectconvertJSONToObject(String input, Class<?> type)protected ObjectconvertToJSON(Object input)protected StringconvertToXML(Object input)protected ObjectconvertXMLToObject(String input, Class<?> type)voidexecuteWorkItem(org.kie.api.runtime.process.WorkItem wi, org.kie.api.runtime.process.WorkItemManager wim)
-
-
-
Field Detail
-
JSON
public static final String JSON
- See Also:
- Constant Field Values
-
XML
public static final String XML
- See Also:
- Constant Field Values
-
FORMAT
public static final String FORMAT
Only supports JSON or XML.- See Also:
- Constant Field Values
-
TYPE
public static final String TYPE
The target object type full qualified name (com.acme.Customer)- See Also:
- Constant Field Values
-
INPUT
public static final String INPUT
The input object of type TYPE or String (if you set toObject)- See Also:
- Constant Field Values
-
RESULT
public static final String RESULT
The resulting object or String (if toObject is false it will be a String).- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ParserWorkItemHandler
public ParserWorkItemHandler()
-
ParserWorkItemHandler
public ParserWorkItemHandler(ClassLoader cl)
-
-
Method Detail
-
abortWorkItem
public void abortWorkItem(org.kie.api.runtime.process.WorkItem wi, org.kie.api.runtime.process.WorkItemManager wim)
-
executeWorkItem
public void executeWorkItem(org.kie.api.runtime.process.WorkItem wi, org.kie.api.runtime.process.WorkItemManager wim)
-
convertToXML
protected String convertToXML(Object input) throws JAXBException
- Throws:
JAXBException
-
convertJSONToObject
protected Object convertJSONToObject(String input, Class<?> type) throws com.fasterxml.jackson.databind.JsonMappingException, IOException
- Throws:
com.fasterxml.jackson.databind.JsonMappingExceptionIOException
-
convertToJSON
protected Object convertToJSON(Object input) throws com.fasterxml.jackson.databind.JsonMappingException, IOException
- Throws:
com.fasterxml.jackson.databind.JsonMappingExceptionIOException
-
-