Skip to content

Instantly share code, notes, and snippets.

@ctataryn
Created June 5, 2014 16:21
Show Gist options
  • Save ctataryn/45dfa25be14921e71e63 to your computer and use it in GitHub Desktop.
Save ctataryn/45dfa25be14921e71e63 to your computer and use it in GitHub Desktop.
@ApiModel("Outage Message")
public class OutageDto {
private String applicationName;
private DateTime outageDate;
private String message;
public OutageDto() {}
public OutageDto(Locale locale, Outage outage) {
this.applicationName = "My App";
this.outageDate = new DateTime(outage.getStartTime());
this.message = LtoUtils.isFrench(locale) ? outage.getFrenchMessage() : outage.getEnglishMessage();
}
@JsonProperty("application_name")
@ApiModelProperty(value = "The name of the Application this Outage is for")
public String getApplicationName() {
return applicationName;
}
public void setApplicationName(String applicationName) {
this.applicationName = applicationName;
}
@JsonSerialize(using = JodaDateTimeSerializer.class)
@JsonProperty("outage_date")
public DateTime getOutageDate() {
return outageDate;
}
public void setOutageDate(DateTime outageDate) {
this.outageDate = outageDate;
}
@JsonProperty("message")
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
@dilipkrish
Copy link

@ctataryn How about making your model annotated like so, i.e. annotating the fields instead of the getters... if that doesnt work try annotating the setters...

@ApiModel("Outage Message")
public class OutageDto {
       @JsonProperty("application_name") 
    private String applicationName;
       @JsonProperty("outage_date")
    private DateTime outageDate;
       @JsonProperty("message") 
    private String message;

    public OutageDto() {}
    public OutageDto(Locale locale, Outage outage) {
        this.applicationName = "My App";
        this.outageDate = new DateTime(outage.getStartTime());
        this.message = LtoUtils.isFrench(locale) ? outage.getFrenchMessage() : outage.getEnglishMessage();
    }


    @ApiModelProperty(value = "The name of the Application this Outage is for")
    public String getApplicationName() {
        return applicationName;
    }

    public void setApplicationName(String applicationName) {
        this.applicationName = applicationName;
    }

    @JsonSerialize(using = JodaDateTimeSerializer.class)
    public DateTime getOutageDate() {
        return outageDate;
    }

    public void setOutageDate(DateTime outageDate) {
        this.outageDate = outageDate;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment