2
votes

I am using dropwizard 1.1.0 with java 8 features. I am also using Immutables package. I am facing a deserialization issue when trying to convert list of profit centres (string list) from JSON to java equivalent.

Error

Can not find a deserializer for non-concrete Collection type [collection type; class com.google.common.collect.ImmutableList, contains [simple type, class java.lang.String]]

Immutable Java class

@Value.Immutable
@JsonSerialize(as = ImmutableReconciliationInputDTO.class)
@JsonDeserialize(as = ImmutableReconciliationInputDTO.class)
public interface ReconciliationInputDTO extends Serializable {

@JsonProperty("date")
@JsonDeserialize(using = LocalDateDeserializer.class)
@JsonSerialize(using = LocalDateSerializer.class)
LocalDate asOfDate();

@JsonProperty("label")
String label();

@JsonProperty("entityId")
String entityId();

@JsonProperty("entityName")
String entityName();

@JsonProperty("departments")
List<String> departments();

Immutables generated the above DTO to a final class with attributes as below

public final class ImmutableReconciliationInputDTO
 implements ReconciliationInputDTO {
private final LocalDate asOfDate;
private final String label;
private final String entityId;
private final String entityName;
private final ImmutableList<String> departments;

In my dropwizard application bootstrap I have registered the below modules

    bootstrap.getObjectMapper().registerModule(new JavaTimeModule());
    bootstrap.getObjectMapper().registerModule(new Jdk8Module());
    bootstrap.getObjectMapper().registerModule(new ParameterNamesModule());

In my POM.xml I am setting the below as my dependencies

<dependency>
    <groupId>com.fasterxml.jackson.module</groupId>
    <artifactId>jackson-module-parameter-names</artifactId>
    <version>2.8.7</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.datatype</groupId>
    <artifactId>jackson-datatype-jdk8</artifactId>
    <version>2.8.7</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.datatype</groupId>
    <artifactId>jackson-datatype-jsr310</artifactId>
    <version>2.8.7</version>
</dependency>
1

1 Answers

4
votes

AFAIK you should include guava as a jackson module also. It is here: guava-module

They also have an example how to integrate it:

registerModule(new GuavaModule())