How to Map one object to another in Java spring boot

1.2k Views Asked by At

I am looking for the way to map the stored proc result to an object:

Stored proc returns Map<String, Object> as :

{
    "O_TOKEN_EXISTS": "true",
    "O_TOKEN_VERIFICATION": "verification",
    "O_PROMOTION_ID": "11223344",
    "O_FFA": "ffa",
    "O_MMI": null,
    "O_VALIDITY_DURATION": 60,
    "O_MOP_ELIGIBILITY": "eligibility"
}

the Object I need to map is look following:

public class ResultObject {

    @JsonProperty("FFA")    
    private String ffa;

    @JsonProperty("ValidityDuration")
    private BigDecimal validityDuration;

    @JsonProperty("Capabilities")
    private List<Capability> capabilities = null;

and Capability looks like

public class Capability {

    @JsonProperty("name")
    private String name;

    @JsonProperty("value")
    private Boolean value;
}

As a result i need to get this :

{
    "FFA": "ffa",
    "ValidityDuration": 60,
    "Capabilities": [
        {
            "name": "MOP",
            "value": true
        },
        {
            "name": "PINVerification",
            "value": true
        },
        {
            "name": "MMI",
            "value": false
        }
    ]
}

How to set the capability is a big question to me, e,g if there is a value for "O_MOP_ELIGIBILITY" in first obj it should set Capability as

{
 "name": "MOP",
 "value": true
 }

if value is not in the first object e.g. "O_MMI": null, i need to set like this:

 {
  "name": "MMI",
  "value": false
  }
0

There are 0 best solutions below