Sagar Pudi
Sagar Pudi

Reputation: 4814

How to retain Long as Number only in JSON instead of String when serializing with Jackson?

I am converting processes map to JSON using jackson 2.6.2 automatically.

   Map<Long,String> processes = new HashMap<>();
    processes.add(1l,"p1");
    processes.add(2l,"p2");

The resultant JSON is coming in String: String format:

{
        "1": "p1",
        "2": "p2"
}

How to retain Long Number as Number only in JSON i.e., Number: String like below:

   {
            1: "p1",
            2: "p2"
    }

Upvotes: 0

Views: 251

Answers (1)

Prathamesh Jagtap
Prathamesh Jagtap

Reputation: 403

Keys of the Javascript objects are always parsed as string.

In object literal terms, key is a property. Properties are strings in JavaScript.

Upvotes: 3

Related Questions