how to serialize long to string with jackson?

ramon_salla picture ramon_salla · Nov 24, 2010 · Viewed 9.2k times · Source

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

any jackson annotation?

thanks.

Answer

fgui picture fgui · Sep 13, 2012

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

@JsonSerialize(using=ToStringSerializer.class)
public long getId() {
    return id;
}