Class 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.73.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.AbstractLogOrThrowWorkItemHandler
    WorkItemHandler that is capable of parsing String to objects and vice-versa. Currently supports only two formats
    • XML
    • JSON
    Here is the list of supported parameters:
    • 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.

    • 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)
      • convertXMLToObject

        protected Object convertXMLToObject​(String input,
                                            Class<?> type)
      • convertJSONToObject

        protected Object convertJSONToObject​(String input,
                                             Class<?> type)
                                      throws com.fasterxml.jackson.databind.JsonMappingException,
                                             IOException
        Throws:
        com.fasterxml.jackson.databind.JsonMappingException
        IOException
      • convertToJSON

        protected Object convertToJSON​(Object input)
                                throws com.fasterxml.jackson.databind.JsonMappingException,
                                       IOException
        Throws:
        com.fasterxml.jackson.databind.JsonMappingException
        IOException