2

I am new here, and I hope that you will help me. I have a javascript function and there i call a function like this:

var criticalDateStart = new Date(1525683802394);
var criticalDateEnd = new Date(1525770202394);

var users = enumerateUsers({
    userId : userId,
    criticalDateStart : criticalDateStart.getTime(),
    criticalDateEnd : criticalDateEnd.getTime(),
});

Furthemore, I have a lambda function on the server, that looks like this:

Function<Object, Object> enumeratePatients = (arg) -> {

        if (arg instanceof ScriptObjectMirror) {
            ScriptObjectMirror _arg = (ScriptObjectMirror) arg;
            Integer userId = (Integer) _arg.get("userId");
            Long criticalDateStart = (Long)_arg.get("criticalDateStart");   
            Long criticalDateEnd = (Long)_arg.get("criticalDateEnd");

            ResteasyClient client = new ResteasyClientBuilder().build();
            ResteasyWebTarget rtarget = client.target(Url);
            Rest rest = rtarget.proxy(Rest.class);
                return rest.enumerateUsers(
                         new EnumerateUserParameter(
                           userId, 
                           criticalDateStart, 
                           criticalDateEnd));
            }
            return null;
        };

But it returns an error

java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.Long.

Where is the problem?

By the way, the error is at the long criticalDateStart and end line.

Jan B.
  • 6,030
  • 5
  • 32
  • 53

2 Answers2

0

It looks like criticalDateStart and criticalDateEnd are doubles, not longs, in your Java code. What you can do:

long criticalDateStart = ((Double)_arg.get("criticalDateStart")).longValue();
long criticalDateEnd = ((Double)_arg.get("criticalDateEnd")).longValue();
assylias
  • 321,522
  • 82
  • 660
  • 783
-1

Try using Double's method longValue().

Long criticalDateStart = ((Double) _arg.get("criticalDateStart")).longValue();
Ahmad Shahwan
  • 1,662
  • 18
  • 29
  • `ScriptObjectMirror` resolve your object as `Double`. While java can convert primitive double to primitive long, its not the case when using corresponding objects. This is simply because `Long` is not a subclass of `Double`. – Ahmad Shahwan May 22 '18 at 12:53
  • 1
    aha, ty, I get it now :) –  May 22 '18 at 12:55