BAEL-1979 Moved the snakeyaml related code to libraries module
This commit is contained in:
parent
e55944b8c1
commit
388645a34c
1
libraries/.gitignore
vendored
1
libraries/.gitignore
vendored
@ -6,3 +6,4 @@
|
||||
|
||||
# Packaged files #
|
||||
*.jar
|
||||
/bin/
|
||||
|
@ -771,6 +771,12 @@
|
||||
<version>${hamcrest-all.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.yaml</groupId>
|
||||
<artifactId>snakeyaml</artifactId>
|
||||
<version>${snakeyaml.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
@ -909,6 +915,7 @@
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<snakeyaml.version>1.21</snakeyaml.version>
|
||||
<googleclient.version>1.23.0</googleclient.version>
|
||||
<crdt.version>0.1.0</crdt.version>
|
||||
<multiverse.version>0.7.0</multiverse.version>
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.baeldung.snakeyaml.model;
|
||||
package com.baeldung.snakeyaml;
|
||||
|
||||
public class Address {
|
||||
private String line;
|
@ -1,4 +1,4 @@
|
||||
package com.baeldung.snakeyaml.model;
|
||||
package com.baeldung.snakeyaml;
|
||||
|
||||
public class Contact {
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.baeldung.snakeyaml.model;
|
||||
package com.baeldung.snakeyaml;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -9,7 +9,6 @@ public class Customer {
|
||||
private Integer age;
|
||||
private List<Contact> contactDetails;
|
||||
private Address homeAddress;
|
||||
private Address officeAddress;
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
@ -49,14 +48,6 @@ public class Customer {
|
||||
|
||||
public void setHomeAddress(Address homeAddress) {
|
||||
this.homeAddress = homeAddress;
|
||||
}
|
||||
|
||||
public Address getOfficeAddress() {
|
||||
return officeAddress;
|
||||
}
|
||||
|
||||
public void setOfficeAddress(Address officeAddress) {
|
||||
this.officeAddress = officeAddress;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
package com.baeldung.snakeyaml;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.StringWriter;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
@ -8,7 +10,7 @@ import org.junit.Test;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
import org.yaml.snakeyaml.nodes.Tag;
|
||||
|
||||
import com.baeldung.snakeyaml.model.Customer;
|
||||
import com.baeldung.snakeyaml.Customer;
|
||||
|
||||
public class JavaToYAMLSerializationUnitTest {
|
||||
|
||||
@ -22,7 +24,8 @@ public class JavaToYAMLSerializationUnitTest {
|
||||
StringWriter writer = new StringWriter();
|
||||
yaml.dump(data, writer);
|
||||
System.out.println(writer.toString());
|
||||
|
||||
String expectedYaml = "name: Silenthand Olleander\nrace: Human\ntraits: [ONE_HAND, ONE_EYE]\n";
|
||||
assertEquals(expectedYaml, writer.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -33,8 +36,9 @@ public class JavaToYAMLSerializationUnitTest {
|
||||
customer.setLastName("McDowell");
|
||||
Yaml yaml = new Yaml();
|
||||
StringWriter writer = new StringWriter();
|
||||
yaml.dump(customer, writer);
|
||||
System.out.println(writer.toString());
|
||||
yaml.dump(customer, writer);
|
||||
String expectedYaml = "!!com.baeldung.snakeyaml.Customer {age: 45, contactDetails: null, firstName: Greg,\n homeAddress: null, lastName: McDowell}\n";
|
||||
assertEquals(expectedYaml, writer.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -44,8 +48,9 @@ public class JavaToYAMLSerializationUnitTest {
|
||||
customer.setFirstName("Greg");
|
||||
customer.setLastName("McDowell");
|
||||
Yaml yaml = new Yaml();
|
||||
yaml.dumpAs(customer, Tag.MAP, null);
|
||||
System.out.println(yaml.dumpAs(customer, Tag.MAP, null));
|
||||
String expectedYaml = "{age: 45, contactDetails: null, firstName: Greg, homeAddress: null, lastName: McDowell}\n";
|
||||
assertEquals(expectedYaml, yaml.dumpAs(customer, Tag.MAP, null));
|
||||
}
|
||||
|
||||
}
|
@ -13,8 +13,8 @@ import org.yaml.snakeyaml.TypeDescription;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
import org.yaml.snakeyaml.constructor.Constructor;
|
||||
|
||||
import com.baeldung.snakeyaml.model.Contact;
|
||||
import com.baeldung.snakeyaml.model.Customer;
|
||||
import com.baeldung.snakeyaml.Contact;
|
||||
import com.baeldung.snakeyaml.Customer;
|
||||
|
||||
public class YAMLToJavaDeserialisationUnitTest {
|
||||
|
||||
@ -23,7 +23,7 @@ public class YAMLToJavaDeserialisationUnitTest {
|
||||
Yaml yaml = new Yaml();
|
||||
InputStream inputStream = this.getClass()
|
||||
.getClassLoader()
|
||||
.getResourceAsStream("customer.yaml");
|
||||
.getResourceAsStream("yaml/customer.yaml");
|
||||
Map<String, Object> obj = yaml.load(inputStream);
|
||||
System.out.println(obj);
|
||||
}
|
||||
@ -33,7 +33,7 @@ public class YAMLToJavaDeserialisationUnitTest {
|
||||
Yaml yaml = new Yaml(new Constructor(Customer.class));
|
||||
InputStream inputStream = this.getClass()
|
||||
.getClassLoader()
|
||||
.getResourceAsStream("customer.yaml");
|
||||
.getResourceAsStream("yaml/customer.yaml");
|
||||
Customer customer = yaml.load(inputStream);
|
||||
System.out.println(customer);
|
||||
}
|
||||
@ -43,7 +43,7 @@ public class YAMLToJavaDeserialisationUnitTest {
|
||||
Yaml yaml = new Yaml();
|
||||
InputStream inputStream = this.getClass()
|
||||
.getClassLoader()
|
||||
.getResourceAsStream("customer_with_type.yaml");
|
||||
.getResourceAsStream("yaml/customer_with_type.yaml");
|
||||
Customer customer = yaml.load(inputStream);
|
||||
System.out.println(customer);
|
||||
}
|
||||
@ -63,7 +63,7 @@ public class YAMLToJavaDeserialisationUnitTest {
|
||||
Yaml yaml = new Yaml(new Constructor(Customer.class));
|
||||
InputStream inputStream = this.getClass()
|
||||
.getClassLoader()
|
||||
.getResourceAsStream("customer_with_contact_details_and_address.yaml");
|
||||
.getResourceAsStream("yaml/customer_with_contact_details_and_address.yaml");
|
||||
Customer customer = yaml.load(inputStream);
|
||||
assertNotNull(customer);
|
||||
assertEquals("John", customer.getFirstName());
|
||||
@ -87,9 +87,6 @@ public class YAMLToJavaDeserialisationUnitTest {
|
||||
assertNotNull(customer.getHomeAddress());
|
||||
assertEquals("Xyz, DEF Street", customer.getHomeAddress()
|
||||
.getLine());
|
||||
assertNotNull(customer.getHomeAddress());
|
||||
assertEquals("Xyz, Office Street", customer.getOfficeAddress()
|
||||
.getLine());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -101,7 +98,7 @@ public class YAMLToJavaDeserialisationUnitTest {
|
||||
Yaml yaml = new Yaml(constructor);
|
||||
InputStream inputStream = this.getClass()
|
||||
.getClassLoader()
|
||||
.getResourceAsStream("customer_with_contact_details.yaml");
|
||||
.getResourceAsStream("yaml/customer_with_contact_details.yaml");
|
||||
Customer customer = yaml.load(inputStream);
|
||||
assertNotNull(customer);
|
||||
assertEquals("John", customer.getFirstName());
|
||||
@ -123,7 +120,7 @@ public class YAMLToJavaDeserialisationUnitTest {
|
||||
Yaml yaml = new Yaml(new Constructor(Customer.class));
|
||||
InputStream inputStream = this.getClass()
|
||||
.getClassLoader()
|
||||
.getResourceAsStream("customers.yaml");
|
||||
.getResourceAsStream("yaml/customers.yaml");
|
||||
int count = 0;
|
||||
for (Object object : yaml.loadAll(inputStream)) {
|
||||
count++;
|
@ -11,8 +11,3 @@ homeAddress:
|
||||
city: "City Y"
|
||||
state: "State Y"
|
||||
zip: 345657
|
||||
officeAddress:
|
||||
line: "Xyz, Office Street"
|
||||
city: "City Y"
|
||||
state: "State Y"
|
||||
zip: 345657
|
@ -0,0 +1,4 @@
|
||||
!!com.baeldung.snakeyaml.Customer
|
||||
firstName: "John"
|
||||
lastName: "Doe"
|
||||
age: 20
|
9
pom.xml
9
pom.xml
@ -549,8 +549,7 @@
|
||||
<module>apache-meecrowave</module>
|
||||
<module>spring-reactive-kotlin</module>
|
||||
<module>jnosql</module>
|
||||
<module>testing-modules/junit-abstract</module>
|
||||
<module>snakeyaml</module>
|
||||
<module>testing-modules/junit-abstract</module>
|
||||
</modules>
|
||||
|
||||
</profile>
|
||||
@ -670,8 +669,7 @@
|
||||
<module>spring-amqp-simple</module>
|
||||
<module>spring-apache-camel</module>
|
||||
<module>spring-batch</module>
|
||||
<module>testing-modules/junit-abstract</module>
|
||||
<module>snakeyaml</module>
|
||||
<module>testing-modules/junit-abstract</module>
|
||||
|
||||
|
||||
<!-- group 2 - Pass, 11-16 min, 42 test failures, 4,020 KB -->
|
||||
@ -1077,8 +1075,7 @@
|
||||
<module>antlr</module>
|
||||
<module>maven-archetype</module>
|
||||
<module>apache-meecrowave</module>
|
||||
<module>testing-modules/junit-abstract</module>
|
||||
<module>snakeyaml</module>
|
||||
<module>testing-modules/junit-abstract</module>
|
||||
|
||||
<!-- problematic -->
|
||||
<!--
|
||||
|
@ -1,29 +0,0 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>snakeyaml</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>snakeyaml</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.yaml</groupId>
|
||||
<artifactId>snakeyaml</artifactId>
|
||||
<version>1.21</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -1,4 +0,0 @@
|
||||
!!com.baeldung.snakeyaml.model.Customer
|
||||
firstName: "John"
|
||||
lastName: "Doe"
|
||||
age: 20
|
Loading…
x
Reference in New Issue
Block a user