Announcing the Saviynt Knowledge Exchange unifying the Saviynt forums, documentation, training,
and more in a single search tool across platforms. Read the announcement here.

Custom Jar to update user in user update rule

rahul_p
Regular Contributor II
Regular Contributor II

Hello Team,

Greetings!!!

I am using custom JAR to update user on specific action, JAR is getting triggered properly. Now I have updated the JSON using JSONObject and when I printed in the logs then its showing the proper updated JSON, same JSON I am returning but the user not getting updated.

I have used following code :

public String updateUser(String userJson) throws JSONException {

JSONObject json = new JSONObject(userJson);
String response=null;

try {

logger.info("*********************INPUT JSON***********************");
logger.info("INPUT "+json);
logger.info("*********************ENDED***********************");

json.put("customproperty43", "THISISREHIRECASE");
response=json.toString();
logger.info("*********************JSON***********************"+response);

}
catch(Exception e) {
logger.info("Exception occurred "+e);
}
return response;

}

 

With this, NO error but user not getting updated, what is proper method to update from JAR?

 

Also I tried using POJO class, where I have defined user attributes,setter and getter in User.java and one response class where I am setting user object. I am using below custom method

Gson gson = new Gson();
JsonObject obj = new JsonParser().parse(userJson).getAsJsonObject();
logger.info("*********************INPUT DATA***********************");
logger.info("Input DATA is "+obj);
logger.info("*********************CLOSED***********************"); User
userData =gson.fromJson(obj, User.class);   //here getting the error
//(User)gson.fromJson(userJson, User.class);
logger.info("*********************FINAL DATA***********************");
logger.info("Input userDATA is "+userData);
logger.info("*********************CLOSED***********************");
userData.setCustomproperty41("ThisIsRehireCase");
logger.info("Set the CP41"); 
response.setUsers(userData);
logger.info("Set the user data");
logger.info("EXITING....."+methodName+" "+CLASS_NAME);

 

With this, I am getting below error :

Exception occurred com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected STRING but was BEGIN_OBJECT

Please help.

Thanks,

Rahul

 

2 REPLIES 2

kishorekumarmb
Saviynt Employee
Saviynt Employee

Hi @rahul_p ,

         The Custom action doesn't have and accept any return object. In jar as only input paramter you will get all user related attributes. If you want to perform any action that needs to be handled in Jar itself.  As a highlevel example if you want to update any saviynt object use saviynt rest api in jar.

By seeing the code I can understand that your trying to update CP43 of user for that in custom jar you have use  "{{url}}/ECM/{{path}}/updateUser" rest api. But that can be easily achieved by update user json by mapping the saviynt connection.

This action is introduced to provide fessibility to use in case of any action that can't be achieved by OOTB.

Thanks

Kishore

 

 

Hi Kishore,

Do you have an explanation for the error message Exception occurred com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected STRING but was BEGIN_OBJECT? We are also running the custom jar current on this error.

We only want to read out the user data.

public void customSAPWriteBack(String userJson) throws JCoException {
              System.out.println("userJson data : " + userJson);
             GsonBuilder builder = new GsonBuilder();
             Gson gson = builder.create();
               User userData = (User)gson.fromJson(userJson, User.class);
            .....}

This worked fine in a previous Saviynt version. Now - with 23.7 - we get this exception as soon as we try to read the JSON object passed to the method.

Must something be adapted in the coding here now with the newer Saviynt version??

Grateful for any idea.

Petra