0
votes

I am working on creating a Mule Anypoint connector using DevKit to connect to an internally developed API. Using the @RestCall annotation, I was able to successfully use my connector in a Mule flow, with the connector returning a String of the following JSON:

{
    "name": "Bryan",
    "email": "[email protected]",
    "uid": "b6fr89dbf6d9156cace5f3c78dc9851d957381ef",
    "email_verified": true
}

I know I could implement a "JSON to Object" transformer in the Mule flow, but I would like for the connector to return a POJO instead. That being said, I modified abstract method annotated by the @RestCall to return an Account object:

@Processor
@RestCall(
        uri="https://api.myservice.com/v2/account", 
        method=HttpMethod.GET, 
        contentType = "application/json")
public abstract Account getUserInformation() throws IOException;  

Just for reference, here is how I defined Account:

package org.mule.modules.myservice.model;

import java.io.Serializable;

public class Account implements Serializable {
    private static final long serialVersionUID = -1L;

    private String name;
    private String email;
    private String uid;
    private boolean emailVerified;

    /**
     * removed getters and setters for brevity
     */
}

However, now that I am trying to return the Account object, I receive the following error:

org.mule.api.transformer.TransformerException: Could not find a transformer to transform "SimpleDataType{type=java.lang.String, mimeType='/'}" to "SimpleDataType{type=org.mule.modules.myservice.model.Account, mimeType='/'}".

I see that there is a @Transformer annotation, but documentation is lacking on how to implement this in regards to working with JSON and/or working within the context of a @RestCall within a Mule connector.

Can anyone offer up advice on how to transform a String of JSON into an Account object within the connector?

2

2 Answers

0
votes

At some point (not where you are pointing at) you are trying to pass an String to an operation that needs Account. Register a transformer for that or transform manually before the operation.

0
votes

I received the following response in another forum and wanted to pass it along:

In order to use DevKit @RestCall with pojos, you need to define the transformers from String to your POJO.

Check this example: https://github.com/pablocabrera85/json-place-holder-connector

For my specific question, this was the type of example I was looking for and indeed worked.