I have a class which has two constructors. I am trying to create instances of this class using a guice factory. If no parameter is passed, then default constructor should be called. If a parameter is passed, then constructor with parameter should be called. But currently even if I pass a parameter to the factory method, still the default constructor is getting called. Constructor with parameter is not at all getting called. Below is my factory class.
public interface MapperFactory {
PigBagMapper createPigBagMapper(@Assisted("pigMetaInfoList") List<String> sourceMetaInfoList);
JsonMapper createJsonMapper(@Assisted("apiName") String apiName) throws EndpointNotFoundException, JsonMapperException;
JsonMapper createJsonMapper();
}
Below are the constructors I am trying to inject.
@AssistedInject
public JsonMapper() {
handlers = new LinkedList<>();
}
@AssistedInject
public JsonMapper(@Assisted("apiName") String apiName) throws EndpointNotFoundException, JsonMapperException {
somelogic();
}
Below is my module binding in Abstract Module implementing class.
install(new FactoryModuleBuilder()
.implement(PigBagMapper.class, PigBagMapperImpl.class)
.implement(JsonMapper.class, JsonMapperImpl.class)
.build(MapperFactory.class));
Below is how I am calling the constructor.
mapperFactory.createJsonMapper(apiName);
What am I doing wrong here? Any help would be much appreciated.
EDIT:
Please note that the JsonMapperImpl class has no constructor. It just has a public method and that's all.