I am using Java 16 and spring-boot (2.5.3) to create a REST api which returns a Long property and also the String version of the Long property.
The Long is created via Javas Random().nextLong()
and the String via toString()
of that Long value.
In the return object I set the Long to prop1 and the String to prop2.
If I debug my code both values inside the return object are the same.
If I look at my response inside the browsers devtools both sometimes are different.
Example: prop2: "8809294616433182964", prop1: 8809294616433183000
Can someone explain the reason for this and how to use a Long without this happening?
If I use Long.valueOf(Random().nextInt())
everything works fine, so it somehow dependents on the size of the long value.
All my objects ids are Long based and I don't want to have a problem with this if the ids get too big.