Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to serialize long to string with jackson?

Tags:

jackson serializes long x = 1234 to {x:1234} For several reasons I need {x:"1234"}

any jackson annotation?

thanks.

like image 401
ramon_salla Avatar asked Nov 24 '10 16:11

ramon_salla


People also ask

Does Jackson use serializable?

Note that Jackson does not use java. io. Serializable for anything: there is no real value for adding that. It gets ignored.

How does ObjectMapper readValue work?

The simple readValue API of the ObjectMapper is a good entry point. We can use it to parse or deserialize JSON content into a Java object. Also, on the writing side, we can use the writeValue API to serialize any Java object as JSON output.

How do you serialize an object in Java Jackson?

let's serialize a java object to a json file and then read that json file to get the object back. In this example, we've created Student class. We'll create a student. json file which will have a json representation of Student object.


1 Answers

The following annotation could be used to serialize a long as a string:

@JsonSerialize(using=ToStringSerializer.class)
public long getId() {
    return id;
}
like image 176
fgui Avatar answered Sep 22 '22 13:09

fgui