Skip to content

Commit

Permalink
Can serialize Suggestion[]
Browse files Browse the repository at this point in the history
  • Loading branch information
JaroslavTulach committed Feb 23, 2023
1 parent 2fbdf75 commit f413b62
Showing 1 changed file with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@

import org.junit.Test;
import scala.Option;
import scala.collection.immutable.Seq;

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()
"SampleModule",
Option.apply("doc"),
Option.apply("html"),
Option.empty(),
Option.empty()
);
final ObjectMapper m = new ObjectMapper().registerModule(new DefaultScalaModule());
String result = m
Expand All @@ -29,4 +30,27 @@ public void testSerdeOfSuggestion() throws Exception {
assertEquals("doc", suggestion.documentation().get());
assertEquals(Suggestion.Module.class, suggestion.getClass());
}

@Test
public void testArraySerdeOfSuggestion() throws Exception {
Object shape = new Suggestion[]{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);

var it = m.readerFor(Suggestion.class).readValues(result);
var suggestion = it.nextValue();
assertEquals(Suggestion.Module.class, suggestion.getClass());
if (suggestion instanceof Suggestion.Module module) {
assertEquals("SampleModule", module.name());
assertEquals("doc", module.documentation().get());
}
}
}

0 comments on commit f413b62

Please sign in to comment.