0

I have a JSON formatted input like

{
    "msisdn" : "<some value>",
    "currentStackType" : "<some value>",
    "msisdnDestination" : "<some value>",
    "ncMigrationStatus" : "<some value>",
    "spid" : "<some value>",
    "ncMigrationTimestamp" :  "2019-01-16 18:04:26"
}

in the class to which I have to deserialize mentioned JSON data fields are named identically to corresponding JSON fields. Also I use @JsonProperty annotations because without them "currentStackType", "msisdnDestination" and "ncMigrationStatus" are not being recognized by ObjectMapper.

After calling ObjectMapper.readValue(json, <MyClassName>.class) I notice that deserialization is successful.

But after that for logging purpose I do the reverse action and observe the following:

{
    "migrationStatus": "<some value>",
    "destination": "<some value>",
    "migrationTimestamp": "<some value>",
    "stackType": "<some value>",
    "msisdn": "<some value>",
    "currentStackType": "<some value>",
    "msisdnDestination": "<some value>",
    "ncMigrationStatus": "<some value>",
    "ncMigrationTimestamp": "2019-01-16 06:04:26",
    "spid": "<some value>"
}

All fields named in low camel case are actually duplicated with "reduced" names.

Is there a way to eliminate this other than renaming JSON properties?

I tried to set PropertyNamingStrategy directly but nothing has changed.

My class looks like

public class ******* {
    @JsonProperty("msisdn")
    @NotBlank(message = "'MSISDN' should not be blank")
    private String msisdn;

    @JsonProperty("currentStackType")
    @NotBlank(message = "'Current Stack Type' should not be blank")
    private String currentStackType;

    @JsonProperty("msisdnDestination")
    @NotBlank(message = "'MSISDN Destination' should not be blank")
    private String msisdnDestination;

    @JsonProperty("ncMigrationStatus")
    @NotBlank(message = "'NC Migration Status' should not be blank")
    private String ncMigrationStatus;

    @JsonProperty("ncMigrationTimestamp")
    @NotNull(message = "'NC Migration Timestamp' should not be null")
    private Date ncMigrationTimestamp;

    @JsonProperty("spid")
    @NotBlank(message = "'SPID' should not be blank")
    private String spid;

    public *******() {
    }

    public void setMSISDN(String val) {
        msisdn = val;
    }

    public String getMSISDN() {
        return msisdn;
    }

    public void setStackType(String val) {
        currentStackType = val;
    }

    public String getStackType() {
        return currentStackType;
    }

    public void setDestination(String val) {
        msisdnDestination = val;
    }

    public String getDestination() {
        return msisdnDestination;
    }

    public void setMigrationStatus(String val) {
        ncMigrationStatus = val;
    }

    public String getMigrationStatus() {
        return ncMigrationStatus;
    }

    public void setMigrationTimestamp(Date val) {
        ncMigrationTimestamp = val;
    }

    public Date getMigrationTimestamp() {
        return ncMigrationTimestamp;
    }

    public void setSPID(String val) {
        spid = val;
    }

    public String getSPID() {
        return spid;
    }
}

I have to hide some details, sorry.

Spielman
  • 31
  • 3

1 Answers1

0

I've found the root cause: names of setter and getter methos must match pattern <set/get><full name of corresponding class data member>.

Camel case must match as well with the only exception: first letter after set/get word has to be capital. Probably some flexibility can be applied using annotations but I haven't tried it yet.

Spielman
  • 31
  • 3