I have the Feature
class as follows:
public class Feature {
private FeatureType featureType;
private Integer featureNumber;
@JsonProperty("isActive")
private boolean isActive;
@JsonProperty("isAutomatedFeature")
private boolean isAutomatedFeature;
private Feature() {
}
public FeatureType getFeatureType() {
return featureType;
}
public Integer getFeatureNumber() {
return featureNumber;
}
@JsonProperty("isActive")
public boolean isActive() {
return isActive;
}
@JsonProperty("isAutomatedFeature")
public boolean isAutomatedFeature() {
return isAutomatedFeature;
}
public static class Builder {
Feature feature=null;
public Builder() {
feature=new Feature();
}
public Builder setFeatureType(FeatureType featureType) {
feature.featureType=featureType;
return this;
}
public Builder setFeatureNumber(Integer featureNumber) {
feature.featureNumber=featureNumber;
return this;
}
@JsonProperty("isActive")
public Builder setIsActive(boolean isActive) {
feature.isActive=isActive;
return this;
}
@JsonProperty("isAutomatedFeature")
public Builder setIsCarryForwardAllowed(boolean isAutomatedFeature) {
feature.isAutomatedFeature=isAutomatedFeature;
return this;
}
public Feature build() {
return feature;
}
}
Now to create a feature we have an api called
api/v1/feature---POST
and its payload will look like below:
"feature":{
"featureType":"XYZ",
"featureType":"40",
"isActive" :true,
"isAutomatedFeature" :true
}
But we can't call this api directly to create a feature so we use RestAssured RequestSpecificationImpl to hit the above API.
It will be something like this
public Response create(Feature feature) {
return post("api/v1/feature",feature);
}
Internally it creates the payload/body for the url and hit the api.So to hit the above method create we need the feature object which I created using builder.
Feature feature=new Feature.Builder().setFeatureType("XYZ").setFeatureNumber(40).setIsActive(true).setIsCarryForwardAllowed(true).build();
I expected the payload to be like above mentioned payload.
But the generated payload is something like this:
"feature":{
"featureType":"XYZ",
"featureType":"40",
"Active" :true,
"AutomatedFeature" :true
}
i.e it removes "is" from "isActive" and "isAutomatedFeature" and make them "Active" and "AutomatedFeature" respectively even when I am using @JsonProperty
,so the api fails.
Can anyone guide me what I am doing wrong or how it can be resolved. Thanks in advance.