possible enhancments

183 views
Skip to first unread message

Farouk Elabady

unread,
Jun 18, 2016, 12:53:45 PM6/18/16
to JMapper Framework
Hi Alessandro Vurro, 
I love you framework and how fast it can get , ans would be great if you can add the following ideas

1 - mix between xml configuration and annotation
digging around the code I found that xml configuration takes higher precedence, which is normal ,so what I wish for is the possiblity to mix between the two for a single class 
for example I have a class called currency that I applied some annotation to it , but I need to make dynamic custom conversion so I needed to do it in xml or api style, but when I do that 
all the annotation is gone , and I am forced to move all the annotation into the xml , would be great if the two can be applied.

2- mapping between destination and source list , for example
JMapper<Dest, Source> mapper = new JMapper<>(Dest.class, Source.class);
mapper.getDestinationList(source); or mapper.getDestination(// list of source and return list of destination);
it will be also great if I can control the collection type , or maybe return a configured map of key value.

3- using functional API and lambda for custom conversion.
to see this through I will apply a simple example with the following code.

public class Currency {
String code;
String name;
int value;
// getters and setters
}

public class Dest {
@JMap
String test;
@JMap("code")
Currency currency;
}

public class Source {
@JMap
String test;
String code;
}


public class Service {
public Currency getCurrency(String code) {
Currency curr = new Currency();
curr.setCode(code);
curr.setName("egypt");
curr.setValue(123);
return curr;
}

}


public static void main(String[] args) {
Source source = new Source();
source.setCode("EGypt");
source.setTest("test  here");
ModelMapper map =  new DefaultModelMapper();
JMapperAPI api = new JMapperAPI();
Service service = new Service();
api.add(JMapperAPI.mappedClass(Dest.class).add(new Attribute("currency").value("code"))
.add(new Conversion("conversion").from("code").to("currency").body(""
+ "System.out.println(\"trying dynamic covnersion\");"
+ "org.test.jmapper2.Service service = new org.test.jmapper2.Service();"
+" org.test.jmapper2.Currency cur = service.getCurrency(${source});"
+ "return cur;"))
);
JMapper<Dest, Source> mapper = new JMapper<>(Dest.class, Source.class, api);
Dest d = mapper.getDestination(source);
}




as from the example what I want to do is to custom convert between a String code , into a currency object, if I use api or xml , it will be erro prone plus , javaassist complaint a lot tell I got it right , and what if I want the vice versa of the conversion to convert from a destination to a source, so my idea is maybe if we used functional api to supply the custom conversion code then that would be great for example
Conversion convert = new Conversion("name")
convert
.from("code").to("currency").body( (source) -> service.getCurrency(source.code));

I will also attach a wrapper class I made to solve this kind of problems , would love your feedback.

Best regards
Farouk Elabady


DefaultModelMapper.java
JCustomConvert.java
ModelMapper.java

milan sonkar

unread,
Aug 20, 2021, 9:18:00 PM8/20/21
to JMapper Framework
Hi All,

This is a great framework, however there are very few updates from last 5 years. Are we planning for a release with new features?

Thanks,
Milan

Reply all
Reply to author
Forward
0 new messages