JAVA-26717:Changes made for Upgrade snakeyaml to latest version (#15284)

This commit is contained in:
Bipin kumar 2023-12-08 16:17:08 +05:30 committed by GitHub
parent 6f9a2c2dfe
commit 18643bc0a0
2 changed files with 19 additions and 11 deletions

View File

@ -98,7 +98,7 @@
</dependencies> </dependencies>
<properties> <properties>
<snakeyaml.version>1.21</snakeyaml.version> <snakeyaml.version>2.2</snakeyaml.version>
<kryo.version>4.0.1</kryo.version> <kryo.version>4.0.1</kryo.version>
<smooks.version>1.7.0</smooks.version> <smooks.version>1.7.0</smooks.version>
<opencsv.version>5.8</opencsv.version> <opencsv.version>5.8</opencsv.version>

View File

@ -1,15 +1,19 @@
package com.baeldung.libraries.snakeyaml; package com.baeldung.libraries.snakeyaml;
import org.junit.Test; import static org.junit.Assert.assertEquals;
import org.yaml.snakeyaml.TypeDescription; import static org.junit.Assert.assertNotNull;
import org.yaml.snakeyaml.Yaml; import static org.junit.Assert.assertTrue;
import org.yaml.snakeyaml.constructor.Constructor;
import java.io.InputStream; import java.io.InputStream;
import java.util.Date; import java.util.Date;
import java.util.Map; import java.util.Map;
import static org.junit.Assert.*; import org.junit.Test;
import org.yaml.snakeyaml.LoaderOptions;
import org.yaml.snakeyaml.TypeDescription;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Constructor;
import org.yaml.snakeyaml.inspector.TagInspector;
public class YAMLToJavaDeserialisationUnitTest { public class YAMLToJavaDeserialisationUnitTest {
@ -27,7 +31,7 @@ public class YAMLToJavaDeserialisationUnitTest {
@Test @Test
public void whenLoadYAMLDocumentWithTopLevelClass_thenLoadCorrectJavaObject() { public void whenLoadYAMLDocumentWithTopLevelClass_thenLoadCorrectJavaObject() {
Yaml yaml = new Yaml(new Constructor(Customer.class)); Yaml yaml = new Yaml(new Constructor(Customer.class,new LoaderOptions()));
InputStream inputStream = this.getClass() InputStream inputStream = this.getClass()
.getClassLoader() .getClassLoader()
.getResourceAsStream("yaml/customer.yaml"); .getResourceAsStream("yaml/customer.yaml");
@ -39,7 +43,11 @@ public class YAMLToJavaDeserialisationUnitTest {
@Test @Test
public void whenLoadYAMLDocumentWithAssumedClass_thenLoadCorrectJavaObject() { public void whenLoadYAMLDocumentWithAssumedClass_thenLoadCorrectJavaObject() {
Yaml yaml = new Yaml(); LoaderOptions loaderoptions = new LoaderOptions();
TagInspector taginspector = tag -> tag.getClassName()
.equals(Customer.class.getName());
loaderoptions.setTagInspector(taginspector);
Yaml yaml = new Yaml(new Constructor(Customer.class, loaderoptions));
InputStream inputStream = this.getClass() InputStream inputStream = this.getClass()
.getClassLoader() .getClassLoader()
.getResourceAsStream("yaml/customer_with_type.yaml"); .getResourceAsStream("yaml/customer_with_type.yaml");
@ -61,7 +69,7 @@ public class YAMLToJavaDeserialisationUnitTest {
@Test @Test
public void whenLoadYAMLDocumentWithTopLevelClass_thenLoadCorrectJavaObjectWithNestedObjects() { public void whenLoadYAMLDocumentWithTopLevelClass_thenLoadCorrectJavaObjectWithNestedObjects() {
Yaml yaml = new Yaml(new Constructor(Customer.class)); Yaml yaml = new Yaml(new Constructor(Customer.class, new LoaderOptions()));
InputStream inputStream = this.getClass() InputStream inputStream = this.getClass()
.getClassLoader() .getClassLoader()
.getResourceAsStream("yaml/customer_with_contact_details_and_address.yaml"); .getResourceAsStream("yaml/customer_with_contact_details_and_address.yaml");
@ -91,7 +99,7 @@ public class YAMLToJavaDeserialisationUnitTest {
@Test @Test
public void whenLoadYAMLDocumentWithTypeDescription_thenLoadCorrectJavaObjectWithCorrectGenericType() { public void whenLoadYAMLDocumentWithTypeDescription_thenLoadCorrectJavaObjectWithCorrectGenericType() {
Constructor constructor = new Constructor(Customer.class); Constructor constructor = new Constructor(Customer.class, new LoaderOptions());
TypeDescription customTypeDescription = new TypeDescription(Customer.class); TypeDescription customTypeDescription = new TypeDescription(Customer.class);
customTypeDescription.addPropertyParameters("contactDetails", Contact.class); customTypeDescription.addPropertyParameters("contactDetails", Contact.class);
constructor.addTypeDescription(customTypeDescription); constructor.addTypeDescription(customTypeDescription);
@ -116,7 +124,7 @@ public class YAMLToJavaDeserialisationUnitTest {
@Test @Test
public void whenLoadMultipleYAMLDocuments_thenLoadCorrectJavaObjects() { public void whenLoadMultipleYAMLDocuments_thenLoadCorrectJavaObjects() {
Yaml yaml = new Yaml(new Constructor(Customer.class)); Yaml yaml = new Yaml(new Constructor(Customer.class, new LoaderOptions()));
InputStream inputStream = this.getClass() InputStream inputStream = this.getClass()
.getClassLoader() .getClassLoader()
.getResourceAsStream("yaml/customers.yaml"); .getResourceAsStream("yaml/customers.yaml");