Spring NumberFormatException: Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long

Simon

I'm not sure if I'm missing something really basic but this is what I would like to do.

I would like to make a rest API call to this address:

https://localhost:8080/fetchlocation?lat=-26.2041028&lng=28.0473051&radius=500

My rest method is:

public void fetchlocation(@RequestParam Long lat, @RequestParam Long lng, @RequestParam int radius){ //fetches location}

I get this error:

"timestamp": 1442751996949, "status": 400, "error": "Bad Request", "exception": "org.springframework.beans.TypeMismatchException",
"message": "Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long'; nested exception is java.lang.NumberFormatException: For input string: \"-26.2041028\"",
"path": "/fetchlocation"

I guess it is because rest API receives the co-ordinates as Strings instead of Longs when I make the GET call. How do I ensure that the rest API gets the Longs and not the String value when the call is made?

I could easily get the method to work when I change the rest API method to take Strings as the parameters, but for type checking, I would prefer to use Longs.

public void fetchlocation(@RequestParam String lat, @RequestParam String lng, @RequestParam String radius){ //fetches location}
Aditya Singh

The number you are trying to convert to java.lang.Long is -26.2041028.

Your number contains a .(decimal). This is not allowed for Longs. You need to use java.lang.Double.

And also succeed your number with an L for Long or a D for Double for static initializations. Even though not required, it makes the code more readable.

Like, -26.2041028D for Double.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

MismatchException: Failed to convert value of type 'java.lang.String' to required type 'int'; nested exception is java.lang.NumberFormatException

From Dev

Spring @Value TypeMismatchException:Failed to convert value of type 'java.lang.String' to required type 'java.lang.Double'

From Dev

@Value -> Failed to convert value of type 'java.lang.String' to required type 'java.lang.Integer'

From Dev

Failed to convert value of type 'java.lang.String' to required type 'java.sql.Date'

From Dev

Failed to convert value of type 'java.lang.String' to required type 'int'; For input string: "save"

From Dev

com.google.firebase.database.DatabaseException: Failed to convert a value of type java.lang.String to long

From Dev

Firebase DatabaseException: Failed to convert value of type java.lang.Long to String

From Dev

Error: Failed to convert property value of type java.lang.String to required type java.util.Date for property dob?

From Dev

Model.addAttribute : Failed to convert value of type 'java.util.Arrays$ArrayList' to required type 'java.lang.String'

From Dev

Failed to convert value of type 'java.lang.String' to required type 'java.util.Date' when sending GET request

From Dev

Thymeleaf and SpringBoot - Failed to convert property value of type [java.lang.String] to required type [java.util.Date] for prope

From Dev

Failed to convert a value of type java.lang.String to int?

From Dev

Failed to convert a value of type java.lang.String to int

From Dev

Resolved [org.springframework.beans.TypeMismatchException String : Failed to convert value of type 'java.lang.String' to required type

From Dev

How to convert value of type 'java.lang.String' to required type 'java.util.Date'?

From Dev

java.lang.NumberFormatException for converting string to long

From Dev

Can't convert object of type java.lang.Long to type

From Dev

Class required a bean of type 'java.lang.String' that could not be found

From Dev

Type mismatch: cannot convert from java.lang.String to String

From Dev

Type missmatch: cannot convert from java.lang.String to String

From Dev

Can't convert object of type java.lang.Long to type java.util.Date

From Dev

Spring forms: "Type [java.lang.String] is not valid for option items"

From Dev

Spring forms: "Type [java.lang.String] is not valid for option items"

From Dev

JSONException: Value of type java.lang.String cannot be converted to JSONObject

From Dev

Value Database of type java.lang.String cannot be converted to JSONObject

From Dev

Value Bundle of type java.lang.String cannot be converted to JSONArray

From Dev

Value Database of type java.lang.String cannot be converted to JSONObject

From Dev

Value Bundle of type java.lang.String cannot be converted to JSONArray

From Dev

Value Connected of type java.lang.String cannot be converted to JSONObject

Related Related

  1. 1

    MismatchException: Failed to convert value of type 'java.lang.String' to required type 'int'; nested exception is java.lang.NumberFormatException

  2. 2

    Spring @Value TypeMismatchException:Failed to convert value of type 'java.lang.String' to required type 'java.lang.Double'

  3. 3

    @Value -> Failed to convert value of type 'java.lang.String' to required type 'java.lang.Integer'

  4. 4

    Failed to convert value of type 'java.lang.String' to required type 'java.sql.Date'

  5. 5

    Failed to convert value of type 'java.lang.String' to required type 'int'; For input string: "save"

  6. 6

    com.google.firebase.database.DatabaseException: Failed to convert a value of type java.lang.String to long

  7. 7

    Firebase DatabaseException: Failed to convert value of type java.lang.Long to String

  8. 8

    Error: Failed to convert property value of type java.lang.String to required type java.util.Date for property dob?

  9. 9

    Model.addAttribute : Failed to convert value of type 'java.util.Arrays$ArrayList' to required type 'java.lang.String'

  10. 10

    Failed to convert value of type 'java.lang.String' to required type 'java.util.Date' when sending GET request

  11. 11

    Thymeleaf and SpringBoot - Failed to convert property value of type [java.lang.String] to required type [java.util.Date] for prope

  12. 12

    Failed to convert a value of type java.lang.String to int?

  13. 13

    Failed to convert a value of type java.lang.String to int

  14. 14

    Resolved [org.springframework.beans.TypeMismatchException String : Failed to convert value of type 'java.lang.String' to required type

  15. 15

    How to convert value of type 'java.lang.String' to required type 'java.util.Date'?

  16. 16

    java.lang.NumberFormatException for converting string to long

  17. 17

    Can't convert object of type java.lang.Long to type

  18. 18

    Class required a bean of type 'java.lang.String' that could not be found

  19. 19

    Type mismatch: cannot convert from java.lang.String to String

  20. 20

    Type missmatch: cannot convert from java.lang.String to String

  21. 21

    Can't convert object of type java.lang.Long to type java.util.Date

  22. 22

    Spring forms: "Type [java.lang.String] is not valid for option items"

  23. 23

    Spring forms: "Type [java.lang.String] is not valid for option items"

  24. 24

    JSONException: Value of type java.lang.String cannot be converted to JSONObject

  25. 25

    Value Database of type java.lang.String cannot be converted to JSONObject

  26. 26

    Value Bundle of type java.lang.String cannot be converted to JSONArray

  27. 27

    Value Database of type java.lang.String cannot be converted to JSONObject

  28. 28

    Value Bundle of type java.lang.String cannot be converted to JSONArray

  29. 29

    Value Connected of type java.lang.String cannot be converted to JSONObject

HotTag

Archive