Jackson ignores properties using the same class

my question is that I want to use the same class to deserialize and re-serialize two different Jsons. I try to explain better. I have these Jsons:

//JSON A
{
    "flavors": [
        {
            "id": "52415800-8b69-11e0-9b19-734f1195ff37",
            "name": "256 MB Server",
            "ram": 256,
            "OS-FLV-DISABLED:disabled":true
            "links": [
                {
                    "rel": "self",
                    "href": "http://www.myexample.com"
                },
                {
                    "rel": "bookmark",
                    "href":"http://www.myexample.com"
                }
            ]
        },
        ...
}
//JSON B
{
    "flavors": [
        {
            "id": "52415800-8b69-11e0-9b19-734f1195ff37",
            "name": "256 MB Server",
            "links": [
                {
                    "rel": "self",
                    "href": "http://www.myexample.com"
                },
                {
                    "rel": "bookmark",
                    "href":"http://www.myexample.com"
                }
            ]
        },
        ...
}

As you can see, JSON B has all the fields JSON A except for "ram" and "OS-FLV-DISABLED: disabled." Used classes:

public class Flavor {

    private String name;
    private List<Link> links;
    private int ram;
    private boolean OS_FLV_DISABLED_disabled;

//constructor and getter/setter
}

@XmlRootElement
public class GetFlavorsResponse {

    private List<Flavor> flavors;
    //constructor and getter/setter
}

Also, just above the getter isOS_FLV_DISABLED_disabled method, I posted the annotation @XmlElement(name = "OS-FLV-DISABLED:disabled") otherwise Jackson does not recognize this property. Here is the situation diagram:

enter image description here

When I get JSON A, there is no problem, the JSON result is again JSON A; but when I get JSON B, the result of serializing the serialization of the process is:

    //JSON C
    {
        "flavors": [
            {
                "id": "52415800-8b69-11e0-9b19-734f1195ff37",
                "name": "256 MB Server",
                "ram": 0,
                "OS-FLV-DISABLED:disabled":false
                "links": [
                    {
                        "rel": "self",
                        "href": "http://www.myexample.com"
                    },
                    {
                        "rel": "bookmark",
                        "href":"http://www.myexample.com"
                    }
                ]
            },
            ...
    }

, , , , Json , 0 "ram" "OS-FLV-: ".

@JsonSerialize(include=JsonSerialize.Inclusion.NON_DEFAULT)

Flavor. , , JSON A, "ram" "OS-FLV-DISABLED: disabled" 0 false ( ), JSON B, . , , , , @JsonView @JsonFilter, , . , .

+4
1

, , , ram OS_FLV_DISABLED_disabled Integer Boolean. , json , . @JsonInclude(Include.NON_NULL), .

+2

All Articles