No constructor / factory

I have this code:

final Person p = new Person(1L); final ObjectMapper mapper = JacksonUtil.INSTANCE.getMapper(); final TypeReference<HashMap<String, Object>> typeMap = new TypeReference<HashMap<String, Object>>() {}; final String personJson= mapper.writeValueAsString(p); mapper.readValue(personJson, typeMap); 

personJson as follows:

 "id" : 1 

Whenever I have a Long type in my Json, it does not work when I try to read it. I have this error:

com.fasterxml.jackson.databind.JsonMappingException: Failed to instantiate a type value [simple type, class org.codehaus.jackson.generated.java.lang.Number] from an integer; no constructor / factory

How can I make it accept type Long ? Is there any function that needs to be enabled in the display device?

+5
source share
1 answer

Create a constructor in Person that takes an integer (and not as long as you). If you definitely want to accept long, try creating a constructor that accepts Number.

+2
source

All Articles