Skip to content

Commit f7594ee

Browse files
committed
XStream-XML to Object
XStream-XML to Object
1 parent c9fbff7 commit f7594ee

26 files changed

Lines changed: 825 additions & 0 deletions

‎xstream-xmlToObject/.project‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>xstream-xmlToObject</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.m2e.core.maven2Builder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
</buildSpec>
19+
<natures>
20+
<nature>org.eclipse.jdt.core.javanature</nature>
21+
<nature>org.eclipse.m2e.core.maven2Nature</nature>
22+
</natures>
23+
</projectDescription>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<customer>
2+
<firstName>XStream</firstName>
3+
<lastName>Java</lastName>
4+
<dob>1986-02-14 04:14:05.874 UTC</dob>
5+
<contactDetailsList>
6+
<ContactDetails contactType="Home">
7+
<mobile>6673543265</mobile>
8+
<landline>0124-2460311</landline>
9+
</ContactDetails>
10+
<ContactDetails contactType="Office">
11+
<mobile>4676543565</mobile>
12+
<landline>0120-223312</landline>
13+
</ContactDetails>
14+
</contactDetailsList>
15+
</customer>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<customer>
2+
<fn>XStream</fn>
3+
<lastName>Java</lastName>
4+
<dob>1986-02-14 03:46:16.381 UTC</dob>
5+
</customer>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<customer>
2+
<firstName>XStream</firstName>
3+
<lastName>Java</lastName>
4+
<dob>1986-02-14 04:14:20.541 UTC</dob>
5+
<ContactDetails contactType="Home">
6+
<mobile>6673543265</mobile>
7+
<landline>0124-2460311</landline>
8+
</ContactDetails>
9+
<ContactDetails contactType="Office">
10+
<mobile>4676543565</mobile>
11+
<landline>0120-223312</landline>
12+
</ContactDetails>
13+
</customer>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<customer>
2+
<firstName>XStream</firstName>
3+
<lastName>Java</lastName>
4+
<dob>1986-02-14 03:46:16.381 UTC</dob>
5+
</customer>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<customer>
2+
<firstName>XStream</firstName>
3+
<lastName>Java</lastName>
4+
<dob>1986-02-14 04:14:20.541 UTC</dob>
5+
<fullName>XStream Java</fullName>
6+
</customer>

‎xstream-xmlToObject/data-file.xml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<com.baeldung.pojo.Customer>
2+
<firstName>XStream</firstName>
3+
<lastName>Java</lastName>
4+
<dob>1986-02-14 03:46:16.381 UTC</dob>
5+
</com.baeldung.pojo.Customer>

‎xstream-xmlToObject/pom.xml‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>com.baeldung</groupId>
6+
<artifactId>xstream-xmlToObject</artifactId>
7+
<version>0.0.1-SNAPSHOT</version>
8+
<packaging>jar</packaging>
9+
10+
<name>xstream-xmlToObject</name>
11+
<url>http://maven.apache.org</url>
12+
13+
<properties>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
</properties>
16+
17+
<dependencies>
18+
<dependency>
19+
<groupId>com.thoughtworks.xstream</groupId>
20+
<artifactId>xstream</artifactId>
21+
<version>1.4.5</version>
22+
</dependency>
23+
24+
<dependency>
25+
<groupId>junit</groupId>
26+
<artifactId>junit</artifactId>
27+
<version>4.12</version>
28+
</dependency>
29+
30+
<dependency>
31+
<groupId>log4j</groupId>
32+
<artifactId>log4j</artifactId>
33+
<version>1.2.17</version>
34+
</dependency>
35+
</dependencies>
36+
</project>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.baeldung.annotation.pojo;
2+
3+
import java.util.Date;
4+
5+
import com.thoughtworks.xstream.annotations.XStreamAlias;
6+
7+
@XStreamAlias("customer")
8+
public class Customer {
9+
10+
@XStreamAlias("fn")
11+
private String firstName;
12+
13+
private String lastName;
14+
15+
private Date dob;
16+
17+
public String getFirstName() {
18+
return firstName;
19+
}
20+
21+
public void setFirstName(String firstName) {
22+
this.firstName = firstName;
23+
}
24+
25+
public String getLastName() {
26+
return lastName;
27+
}
28+
29+
public void setLastName(String lastName) {
30+
this.lastName = lastName;
31+
}
32+
33+
public Date getDob() {
34+
return dob;
35+
}
36+
37+
public void setDob(Date dob) {
38+
this.dob = dob;
39+
}
40+
41+
@Override
42+
public String toString() {
43+
return "Customer [firstName=" + firstName + ", lastName=" + lastName
44+
+ ", dob=" + dob + "]";
45+
}
46+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.baeldung.annotation.pojo;
2+
3+
import java.util.Date;
4+
5+
import com.thoughtworks.xstream.annotations.XStreamAlias;
6+
import com.thoughtworks.xstream.annotations.XStreamOmitField;
7+
8+
9+
@XStreamAlias("customer")
10+
public class CustomerOmitField {
11+
12+
@XStreamOmitField
13+
private String firstName;
14+
15+
private String lastName;
16+
17+
private Date dob;
18+
19+
public String getFirstName() {
20+
return firstName;
21+
}
22+
23+
public void setFirstName(String firstName) {
24+
this.firstName = firstName;
25+
}
26+
27+
public String getLastName() {
28+
return lastName;
29+
}
30+
31+
public void setLastName(String lastName) {
32+
this.lastName = lastName;
33+
}
34+
35+
public Date getDob() {
36+
return dob;
37+
}
38+
39+
public void setDob(Date dob) {
40+
this.dob = dob;
41+
}
42+
43+
@Override
44+
public String toString() {
45+
return "CustomerOmitAnnotation [firstName=" + firstName + ", lastName="
46+
+ lastName + ", dob=" + dob + "]";
47+
}
48+
49+
50+
}

0 commit comments

Comments
 (0)