I wrote my backend in Java, and the endpoint is hit with a request body. The endpoint has a JSON body that looks like this

```
{"id": 1234, "data": {...}}

```

Now, I'm getting the request data, and storing it by the id. I want to save the ids' as longs, however, the values can be anywhere from int-valid to long-valid.

I'm using the Spring framework in order to save it. The function looks like this

```
public String getData (@RequestBody JSONObject jsonRequest) {
    Long id_long = (Long) jsonRequest.get("id"); 

```

However, I get this error 

```
java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Long

```

This is where I'm stuck. Sometimes the id value will be valid like 1234L, or a really long number which is in long range. However, sometimes it is int range. I haven't used Java that much so I was wondering how to do the cast properly so I always get a long.