2015-08-07 17 views
5

ho questo codice:no-int-arg singolo costruttore/fabbrica metodo

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 è come:

"id" : 1 

Ogni volta che ho un Long type nel mio JSON, non funziona quando provo a leggerlo Ho questo errore:

com.fasterxml.jackson.databind.JsonMappingException: Can not instantiate value of type [simple type, class org.codehaus.jackson.generated.java.lang.Number] from Integral number; no single-int-arg constructor/factory method

Come posso farlo accettare il tipo Long? C'è qualche funzione da abilitare nel mapper?

risposta

1

Creare un costruttore in Persona che accetta un numero intero (e non tanto tempo come voi). Se vuoi decisamente accettare un lungo, prova a creare un costruttore che accetta un numero.

Problemi correlati