mercredi 13 avril 2016

How do serializers know when a class has to be considered "primitive"?

Let's take for example jackson serializer and say we have a class like this:

public class Car {
    private String brand;
    private Integer weight;
}

If we serialize this we'll get for example:

{
    "brand": "Fiat",        
    "weight": 50
}

But how did it know that String is not an object composed of different primitive values? I mean it has properties inside, and so does the Integer class. Then why did it not serialize like this?

{
    "brand": {
        "value": [  // primitive char[] inside String
            "F",
            "i",
            "a",
            "t",
        ],
        "hash": xxx // primitive int inside String
    }       
    "weight": {
        "value": 50 // primitive int inside Integer
    }
}





Aucun commentaire:

Enregistrer un commentaire