javajsonrestresponsejbpm

Convert json rest response to Data Object jBPM (Unable to transform respose to object)


I am dealing with jBPM 7.22.0.Final.

I use the service task REST to get response from this api https://reqres.in/api/users/1

{
  "data": {
    "id": 1,
    "email": "george.bluth@reqres.in",
    "first_name": "George",
    "last_name": "Bluth",
    "avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/calebogden/128.jpg"
  }
}

I want to get this response into an Object, so I created this class (or Data Object as called in jBPM):

package com.bechirspace.testproject;

/**
 * This class was automatically generated by the data modeler tool.
 */

    public class data implements java.io.Serializable {



static final long serialVersionUID = 1L;

    private Integer id;
    private java.lang.String email;
    private java.lang.String first_name;
    private java.lang.String last_name;
    private java.lang.String avatar;

    public data() {
    }

    public java.lang.String getEmail() {
        return this.email;
    }

    public void setEmail(java.lang.String email) {
        this.email = email;
    }

    public java.lang.String getFirst_name() {
        return this.first_name;
    }

    public void setFirst_name(java.lang.String first_name) {
        this.first_name = first_name;
    }

    public java.lang.String getLast_name() {
        return this.last_name;
    }

    public void setLast_name(java.lang.String last_name) {
        this.last_name = last_name;
    }

    public java.lang.String getAvatar() {
        return this.avatar;
    }

    public void setAvatar(java.lang.String avatar) {
        this.avatar = avatar;
    }

    public java.lang.Integer getId() {
        return this.id;
    }

    public void setId(java.lang.Integer id) {
        this.id = id;
    }

    public data(java.lang.Integer id, java.lang.String email,
            java.lang.String first_name, java.lang.String last_name,
            java.lang.String avatar) {
        this.id = id;
        this.email = email;
        this.first_name = first_name;
        this.last_name = last_name;
        this.avatar = avatar;
    }

}

and I created a global variable in jBPM called res having the type of this Data Object in which I want to store my response. So in the 'Assignments' of my REST service task , I have what is in the screenshot.

enter image description here

as you see I want to store the result into my res variable of type Data (which I created), and I put in ResultClass my class type that I want to be converted in (com.bechirspace.testproject.data). But it doesn't work, I can build and deploy successfully, but when I want to start a "New Process Instance" it shows this message Error

    Unable to complete your request. The following exception occurred:
     "Unable to create response: [src.main.resources.testProcess:1,434 - REST:7]
 -- java.lang.RuntimeException: Unable to transform respose to object".

PS: I can print my response if I assign it into a String variable, so the problem is in converting the response, not in getting it.

you might say that it is a duplicated question (Map jBPM REST response to Custom Object), but I didn't find a clear answer, can any one help?


Solution

  • Well, I created another Data Object called Person with attribute "data", and changed the Result and ResultClass to this new class. I had to follow the same structure as my json respone, which is an object, having an object attribute called data which has the remaining attributes.

    package com.bechirspace.testproject;
    
    /**
     * This class was automatically generated by the data modeler tool.
     */
    
    public class Person implements java.io.Serializable {
    
        static final long serialVersionUID = 1L;
    
        private com.bechirspace.testproject.data data;
    
        public Person() {
        }
    
        public com.bechirspace.testproject.data getData() {
            return this.data;
        }
    
        public void setData(com.bechirspace.testproject.data data) {
            this.data = data;
        }
    
        public Person(com.bechirspace.testproject.Data data) {
            this.data = data;
        }
    
    
    }