From 2fbdf75f9490b82b997e058dc53831032a568d2c Mon Sep 17 00:00:00 2001 From: Jaroslav Tulach Date: Thu, 23 Feb 2023 17:24:25 +0100 Subject: [PATCH] Using Jackson to serialize and deserialize Suggestion.Module --- .../compiler/test/context/JacksonTest.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 engine/runtime/src/test/java/org/enso/compiler/test/context/JacksonTest.java diff --git a/engine/runtime/src/test/java/org/enso/compiler/test/context/JacksonTest.java b/engine/runtime/src/test/java/org/enso/compiler/test/context/JacksonTest.java new file mode 100644 index 000000000000..3c3af930741c --- /dev/null +++ b/engine/runtime/src/test/java/org/enso/compiler/test/context/JacksonTest.java @@ -0,0 +1,32 @@ +package org.enso.compiler.test.context; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.module.scala.DefaultScalaModule; +import org.enso.polyglot.Suggestion; +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import scala.Option; + +public class JacksonTest { + + @Test + public void testSerdeOfSuggestion() throws Exception { + Object shape = new Suggestion.Module( + "SampleModule", + Option.apply("doc"), + Option.apply("html"), + Option.empty(), + Option.empty() + ); + final ObjectMapper m = new ObjectMapper().registerModule(new DefaultScalaModule()); + String result = m + .writerWithDefaultPrettyPrinter() + .writeValueAsString(shape); + + Suggestion suggestion = m.readerFor(Suggestion.class).readValue(result); + assertEquals("SampleModule", suggestion.name()); + assertEquals("doc", suggestion.documentation().get()); + assertEquals(Suggestion.Module.class, suggestion.getClass()); + } +}