Endpoints and numbers
Hi,
I have an important issue with endpoints and numbers. All numbers above 1000 are transformed in 1 000 with a space between "1" and "000". So when I want to make simple rest calls with a number (user.id for instance), it fails when it's higher than 999.
Example: I want the last messages written by the user whose id is 6207.
"/users/id/${user.id}/posts/latest" or "/users/id/" + user.id + "/posts/latest"
will give
"/users/id/6 207/posts/latest" instead of "/users/id/6207/posts/latest"
I've also tested it with the freemarker '?number' function. It also fails to give 1000 without space.
Meanwhile, I've discovered this article:
https://lithosphere.lithium.com/t5/developers-discussion/user-id-number-format-issue/m-p/112673#M4135
Which was close to my issue. So I tried user.id?c and it worked well!
But everything is a bit messy in my head.
For instance, if I want to transform a string to a number, should I use "?number?c" or just "?c" ?
Why ?number and int don't behave the same way in endpoints than in custom components?
Thanks for your help!
Henrik
?number converts a string to a number (see http://freemarker.org/docs/ref_builtins_string.html#ref_builtin_number)
?c converts a number to a computer-readable string (see http://freemarker.org/docs/ref_builtins_number.html#ref_builtin_c)
Numbers can't be displayed, or treated as a string, without first being converted to a string.If you try to include a number in the output of a custom component/endpoint, FreeMarker will automatically try to convert it to a string, using location-based rules.
FreeMarker provides a few different functions to let you convert a number to a string whilst controlling the format. These are all documented on this page:
http://freemarker.org/docs/ref_builtins_number.html
user.id is a number, not a string, so it needs to be converted to a string before you can include it in the output, or use it within another string (like when creating REST API URLs).