ankit
ankit

Reputation: 2845

how to parse some field of json spring boot

I have json with following fields:

       {
            "id": "MSNVK13LWEWV91",
            "country": "india",
            "name": "cooktop test products",
            "id_brand": "7fbdea31-a2bf-437b-8697-72edfb7fe673",  
            "product_type": "visible"
        }

But i want only country and id to deserialize in spring boot with fasterxml.jackson.

Upvotes: 1

Views: 41

Answers (1)

AKA
AKA

Reputation: 638

You can use @JsonIgnoreProperties( ignoreUnknown = true ) in you DTO:

@Data
@JsonInclude( JsonInclude.Include.NON_NULL )
@JsonIgnoreProperties( ignoreUnknown = true )
public class ProductVO
{
    private String id;
    @JsonProperty( "country" )
    private double country;
}

Hope this will help you in spring boot.

Upvotes: 2

Related Questions