var String actor1_movie1_rating = transform("JSONPATH", "$.result.movies.[0]['rating']", json_actor1_movies)
my if condition
if (actor1_movie1_rating.startsWith("{"))
{
Item_actor1_movie1_rating_search.postUpdate("0")
}
else
{
if (actor1_movie1_rating >= 0 && actor1_movie1_rating <= 2 )
{
Item_actor1_movie1_rating_search.sendCommand("/static/rating0.png")
}
if (actor1_movie1_rating >= 2 && actor1_movie1_rating <= 4 )
{
Item_actor1_movie1_rating_search.sendCommand("/static/rating1.png")
}
if (actor1_movie1_rating >= 4 && actor1_movie1_rating <= 6 )
{
Item_actor1_movie1_rating_search.sendCommand("/static/rating2.png")
}
if (actor1_movie1_rating >= 6 && actor1_movie1_rating <= 8 )
{
Item_actor1_movie1_rating_search.sendCommand("/static/rating3.png")
}
if (actor1_movie1_rating >= 8 && actor1_movie1_rating <= 10 )
{
Item_actor1_movie1_rating_search.sendCommand("/static/rating4.png")
}
if (actor1_movie1_rating == 10 )
{
Item_actor1_movie1_rating_search.sendCommand("/static/rating5.png")
}
}```
then i get :
2021-04-14 21:59:19.345 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'Json_movies_by_actors_search-1' failed: class java.lang.Integer cannot be cast to class java.lang.String (java.lang.Integer and java.lang.String are in module java.base of loader 'bootstrap') in Json_movies_by_actors_search
the only thing i do with the rating is to see if a
"{" is present by checking whether the var starts with "{".
if the value in the var is not "{" then I compare the values in order to write certain paths in an item.
But I can't get rid of the error.
I was interested in this secret error message, including the JSON, in order to find out why the transformation failed.
but maybe you don’t care, fair enough.
But anyway … var String actor1_movie1_rating = transform( ...
always returns a string, which is why you parsed it to a number in your original rule.
Now you don’t parse it, so if (actor1_movie1_rating >= 0 ...
always fails because you cannot directly compare a string with a number like 0.
Looking for “{” to see if the transformation failed is a good idea!
actor1_movie1_rating is neither Number nor String, but an object. Now you can check if it’s of Type Number or not. I have to admit I did not check wether it works or not.