My objects
Public void Student(){
private string name;
private int age;
}
Public void ClassRoom(){
private string roomNo;
private Student student; //Student Object
}
Public void School(){
private string roomNo;
private String student; //String student
}
I have an interface
@Mapper(componentModel = "jsr330", unmappedTargetPolicy = ReportingPolicy.IGNORE, builder = @Builder(disableBuilder = true))
public interface TestjkMapper {
@Named("convertObjToString")
static String convertObjToString(Student student) {
return new Gson.tojson(student)
}
@Mapping(source = "student", target = "student",qualifiedByName = "convertObjToString")
School mapClassRoomToSchool(@NonNull ClassRoom classRoom);
}
I am planning to inject that gson instead of new Gson()
As per this How can i combine Guice and Mapstruct?
I tried to make changes but not sure where to add that
@Inject
Gson gson
I tried like this
public interface TestjkMapper {
@Inject
Gson gson
@Named("authorityToMap")
static Map authorityToMap(Authority authority) {
return gson.tojson(authority.tostring())
}
}
I am getting compiler error as below
variable gson might not have been initialized
how to inject correctly inside that interface
Here also
bind(TestjkMapper.class).to(TestjkMapperImpl.class)
TestjkMapper - My interface
TestjkMapperImpl - This is generated at runtime. So not sure how to bind this
Exact question:
How to convert Student object
to Student String
using guice injected gson