Skip to content

Commit d430a99

Browse files
author
vedenin
committed
Add Hello Worlds for Bean Mapping lib
1 parent 60e159d commit d430a99

File tree

24 files changed

+642
-40
lines changed

24 files changed

+642
-40
lines changed

helloworlds/1.1-common-frameworks-and-lib/quasar/pom.xml

+4-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
<project xmlns="http://maven.apache.org/POM/4.0.0"
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5-
<parent>
6-
<artifactId>1.1-common-frameworks</artifactId>
7-
<groupId>com.github.vedenin</groupId>
8-
<version>0.01</version>
9-
</parent>
5+
6+
<groupId>com.github.vedenin</groupId>
7+
<version>0.01</version>
8+
109
<modelVersion>4.0.0</modelVersion>
1110

1211
<artifactId>quasar</artifactId>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.github.vedenin</groupId>
8+
<artifactId>dozer</artifactId>
9+
<version>0.01</version>
10+
<name>Bean mapping :: Dozer</name>
11+
12+
13+
<dependencies>
14+
<dependency>
15+
<groupId>net.sf.dozer</groupId>
16+
<artifactId>dozer</artifactId>
17+
<version>5.5.1</version>
18+
</dependency>
19+
</dependencies>
20+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package mapstruct;
2+
3+
import org.dozer.DozerBeanMapper;
4+
import org.dozer.Mapper;
5+
import org.dozer.Mapping;
6+
7+
/**
8+
* Hello World that show simple annotation mapping
9+
*
10+
* Created by vedenin on 16.04.16.
11+
*/
12+
public class DozerHelloWorldAnnotation {
13+
public static class Source {
14+
private String message;
15+
16+
public Source(String message) {
17+
this.message = message;
18+
}
19+
20+
@Mapping("text")
21+
public String getMessage() {
22+
return message;
23+
}
24+
}
25+
26+
public static class Destination {
27+
private String text;
28+
29+
public String getText() {
30+
return text;
31+
}
32+
33+
public void setText(String text) {
34+
this.text = text;
35+
}
36+
37+
public void print() {
38+
System.out.println(text);
39+
}
40+
}
41+
42+
public static void main(String[] args) {
43+
// init mapper
44+
Mapper mapper = new DozerBeanMapper();
45+
46+
// convert
47+
Source source = new Source("Hello World!");
48+
Destination destObject = mapper.map(source, Destination.class);
49+
destObject.print(); // print Hello World!
50+
}
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package mapstruct;
2+
3+
import org.dozer.DozerBeanMapper;
4+
import org.dozer.loader.api.BeanMappingBuilder;
5+
6+
import static org.dozer.loader.api.TypeMappingOptions.mapNull;
7+
8+
/**
9+
* Hello World that show simple mapping using api
10+
*
11+
* Created by vedenin on 16.04.16.
12+
*/
13+
public class DozerHelloWorldApi {
14+
public static class Source {
15+
private String message;
16+
17+
public Source(String message) {
18+
this.message = message;
19+
}
20+
21+
public String getMessage() {
22+
return message;
23+
}
24+
}
25+
26+
public static class Destination {
27+
private String text;
28+
29+
public String getText() {
30+
return text;
31+
}
32+
33+
public void setText(String text) {
34+
this.text = text;
35+
}
36+
37+
public void print() {
38+
System.out.println(text);
39+
}
40+
}
41+
42+
public static void main(String[] args) {
43+
// init mapper
44+
BeanMappingBuilder builder = new BeanMappingBuilder() {
45+
protected void configure() {
46+
mapping(Source.class, Destination.class)
47+
.fields("message", "text");
48+
}
49+
};
50+
DozerBeanMapper mapper = new DozerBeanMapper();
51+
mapper.addMapping(builder);
52+
53+
// convert
54+
Source source = new Source("Hello World!");
55+
Destination destObject = mapper.map(source, Destination.class);
56+
destObject.print(); // print Hello World!
57+
}
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package mapstruct;
2+
3+
import org.dozer.DozerBeanMapper;
4+
5+
import java.util.ArrayList;
6+
import java.util.List;
7+
8+
/**
9+
* Hello World that show simple xml mapping
10+
*
11+
* Created by vedenin on 16.04.16.
12+
*/
13+
public class DozerHelloWorldXML {
14+
public static class Source {
15+
private String message;
16+
17+
public Source(String message) {
18+
this.message = message;
19+
}
20+
21+
public String getMessage() {
22+
return message;
23+
}
24+
}
25+
26+
public static class Destination {
27+
private String text;
28+
29+
public String getText() {
30+
return text;
31+
}
32+
33+
public void setText(String text) {
34+
this.text = text;
35+
}
36+
37+
public void print() {
38+
System.out.println(text);
39+
}
40+
}
41+
42+
public static void main(String[] args) {
43+
new DozerHelloWorldXML().test();
44+
}
45+
46+
private void test() {
47+
// init mapper
48+
List<String> myMappingFiles = new ArrayList<String>();
49+
myMappingFiles.add("mapping.xml");
50+
DozerBeanMapper mapper = new DozerBeanMapper();
51+
mapper.setMappingFiles(myMappingFiles);
52+
53+
// convert
54+
Source source = new Source("Hello World!");
55+
Destination destObject = mapper.map(source, Destination.class);
56+
destObject.print(); // print Hello World!;
57+
}
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<mappings xmlns="http://dozer.sourceforge.net"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://dozer.sourceforge.net
5+
http://dozer.sourceforge.net/schema/beanmapping.xsd">
6+
7+
<mapping>
8+
<class-a>mapstruct.DozerHelloWorldXML.Source</class-a>
9+
<class-b>mapstruct.DozerHelloWorldXML.Destination</class-b>
10+
<field>
11+
<a>message</a>
12+
<b>text</b>
13+
</field>
14+
</mapping>
15+
</mappings>
16+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.github.vedenin</groupId>
8+
<artifactId>mapstruct</artifactId>
9+
<version>0.01</version>
10+
<name>Bean mapping :: MapStruct</name>
11+
12+
13+
<properties>
14+
<org.mapstruct.version>1.0.0.Final</org.mapstruct.version>
15+
</properties>
16+
<dependencies>
17+
<dependency>
18+
<groupId>org.mapstruct</groupId>
19+
<artifactId>mapstruct</artifactId>
20+
<version>${org.mapstruct.version}</version>
21+
</dependency>
22+
<!-- Use this with Java 8 and beyond -->
23+
<dependency>
24+
<groupId>org.mapstruct</groupId>
25+
<artifactId>mapstruct-jdk8</artifactId>
26+
<version>${org.mapstruct.version}</version>
27+
</dependency>
28+
</dependencies>
29+
<build>
30+
<plugins>
31+
<plugin>
32+
<groupId>org.bsc.maven</groupId>
33+
<artifactId>maven-processor-plugin</artifactId>
34+
<version>2.2.4</version>
35+
<configuration>
36+
<defaultOutputDirectory>
37+
${project.build.directory}/generated-sources
38+
</defaultOutputDirectory>
39+
<processors>
40+
<processor>org.mapstruct.ap.MappingProcessor</processor>
41+
</processors>
42+
</configuration>
43+
<executions>
44+
<execution>
45+
<id>process</id>
46+
<phase>generate-sources</phase>
47+
<goals>
48+
<goal>process</goal>
49+
</goals>
50+
</execution>
51+
</executions>
52+
<dependencies>
53+
<dependency>
54+
<groupId>org.mapstruct</groupId>
55+
<artifactId>mapstruct-processor</artifactId>
56+
<version>${org.mapstruct.version}</version>
57+
</dependency>
58+
</dependencies>
59+
</plugin>
60+
</plugins>
61+
</build>
62+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package mapstruct;
2+
3+
4+
import org.mapstruct.Mapper;
5+
import org.mapstruct.Mapping;
6+
7+
/**
8+
* Hello World that show simple annotation mapping
9+
*
10+
* Before run use maven install
11+
* Created by vedenin on 16.04.16.
12+
*/
13+
public class MapStructHelloWorld {
14+
public static class Source {
15+
private String message;
16+
17+
public Source(String message) {
18+
this.message = message;
19+
}
20+
21+
public String getMessage() {
22+
return message;
23+
}
24+
}
25+
26+
public static class Destination {
27+
private String text;
28+
29+
public String getText() {
30+
return text;
31+
}
32+
33+
public void setText(String text) {
34+
this.text = text;
35+
}
36+
37+
public void print() {
38+
System.out.println(text);
39+
}
40+
}
41+
42+
@Mapper
43+
public interface TestMapper {
44+
@Mapping(source = "message", target = "text")
45+
Destination sourceToDestination(Source source);
46+
}
47+
48+
public static void main(String[] args) {
49+
// convert
50+
Source source = new Source("Hello World!");
51+
Destination destObject = new TestMapperImpl().sourceToDestination(source);
52+
destObject.print(); // print Hello World!
53+
}
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.github.vedenin</groupId>
8+
<artifactId>modelmapper</artifactId>
9+
<version>0.01</version>
10+
<name>Bean mapping :: ModelMapper</name>
11+
12+
13+
<dependencies>
14+
<dependency>
15+
<groupId>org.modelmapper</groupId>
16+
<artifactId>modelmapper</artifactId>
17+
<version>0.7.5</version>
18+
</dependency>
19+
</dependencies>
20+
</project>

0 commit comments

Comments
 (0)