-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Using Jackson to serialize and deserialize Suggestion.Module
- Loading branch information
1 parent
8f7314e
commit 2fbdf75
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
engine/runtime/src/test/java/org/enso/compiler/test/context/JacksonTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
} |