I have a parent class and a child class and I am using @SuperBuilder
to build the child object, but seemingly it is not initializing at all.
My parent class looks like this:
@Getter
@Setter
@Component
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@SuperBuilder
public class MessageResponse {
String responseMessage;
}
My child class looks like this:
@Getter
@Setter
@Component
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@SuperBuilder
public class ListResponse extends MessageResponse {
List<Item> itemList;
int itemCount;
}
Where Item is a Serializable
class.
Initially the ListResponse
is
itemList = null
itemCount = 0
responseMessage = null
When I try to build ListResponse
using builder, it does not change the ListResponse
object at all. I am trying to build as
//listResponse is @Autowired from Spring and is initially as shown above.
List<Item> itemList = getItems(); // It returns a list of 15 items, i have checked in debugger, It does.
listResponse.builder()
.bucketList(itemList)
.responseMessage("Item List.")
.bucketCount(itemList.size())
.build();
Even after execution of .build()
the contents of this listResponse
object is still (null, 0 , null)
.
I tried to search other references regarding @SuperBuilder
and @Builder
but got no result. Can someone please point out what is going wrong here?