I want to extend my builder pattern class. below is my existing class.
@JacksonRootElement(localName="Test")
@JsonDeserialize(builder = Test.Builder.class)
public class Test{
@JacksonXmlProperty(localName = "TRAIN")
private final List<Train> trainDetails;
@JacksonXmlProperty(localName = "NAME")
private final String name;
@JacksonXmlProperty(localName = "DETAIL_TRAIN", isAttribute = true)
private final Optional<String> detail;
private Test(final Builder builder) {
///field declaration
}
public static Builder builder() {
return new Builder();
}
//getters, hashcode and equals, toString
public Builder toBuilder() {
return builder()
.withTrainDetails(trainDetails)
.withName(name)
.withDetail(detail.orElse(null));
}
public static final class Builder {
private List<Train> trainDetails = ImmutableList.of();
private Optional<String> name = Optional.empty();
private Optional<String> detail = Optional.empty();
private Builder() {
}
//builder methods
public Test build() {
return new Test(this);
}
}
}
Also my train class has like below:
public class Train {
'
private String number;
//builders
}
Here I want to create a new class with same properties in Test class and only change in Test class is @JacksonRootElement is different @JacksonRootElement(localName = "Test123")
. Also in Train class I want to extend it with new field code instead of number.
Anyone please help me to achieve this
Aucun commentaire:
Enregistrer un commentaire