When deserializing a JSON list structure on to a Java class with a property of type IndexedSeq, you get a JsonMappingException because it's trying to coerce a List$Cons on to IndexedSeq. It works fine if the java type is Array or Seq.
Test case:
public class IndexedSeqTest {
private final ObjectMapper objectMapper = new ObjectMapper()
.registerModule(new VavrModule());
@Test
public void test() throws Exception {
final String json = "{\"items\":[\"foo\"]}";
final Model model = objectMapper.readValue(json, Model.class);
assertEquals(Array.of("foo"), model.getItems());
}
@JsonDeserialize
static class Model {
IndexedSeq<String> items;
public Seq<String> getItems() {
return items;
}
}
}
The problem here appears to be SeqDeserializer, which is checking to see if the property is one of Array, Queue, Stream or Vector, and if it's none of those then it creates a List. Effectively, it's assuming that if the type is neither of those options, then it must be a Seq.
The fix could be to add a clause to SeqDeserializer so that if the type is ArrayorIndexedSeq, then then create an Array.
When deserializing a JSON list structure on to a Java class with a property of type
IndexedSeq
, you get aJsonMappingException
because it's trying to coerce aList$Cons
on toIndexedSeq
. It works fine if the java type isArray
orSeq
.Test case:
The problem here appears to be
SeqDeserializer
, which is checking to see if the property is one ofArray
,Queue
,Stream
orVector
, and if it's none of those then it creates aList
. Effectively, it's assuming that if the type is neither of those options, then it must be aSeq
.The fix could be to add a clause to
SeqDeserializer
so that if the type isArray
orIndexedSeq
, then then create an Array.