1

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.

SanQA
  • 233
  • 3
  • 9
  • Which version of RA, Jackson are you using? I have nothing wrong in my end. And one more thing, this line `public Builder setCreditCycle(FeatureType featureType)` seems wrong. – lucas-nguyen-17 Oct 15 '22 at 15:58
  • Yes,Changed the original name with demo names,left that alone,changed that now. – SanQA Oct 15 '22 at 18:25
  • please re-read my comment. No issue on my machine. – lucas-nguyen-17 Oct 16 '22 at 11:40
  • Does this answer your question? [Jackson renames primitive boolean field by removing 'is'](https://stackoverflow.com/questions/32270422/jackson-renames-primitive-boolean-field-by-removing-is) – kaweesha Oct 28 '22 at 19:02

0 Answers0