Skip to content

Commit

Permalink
Using Jackson to serialize and deserialize Suggestion.Module
Browse files Browse the repository at this point in the history
  • Loading branch information
JaroslavTulach committed Feb 23, 2023
1 parent 8f7314e commit 2fbdf75
Showing 1 changed file with 32 additions and 0 deletions.
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());
}
}

0 comments on commit 2fbdf75

Please sign in to comment.