2

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>
serah
  • 2,057
  • 7
  • 36
  • 56

1 Answers1

4

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())
NoobEditor
  • 15,563
  • 19
  • 81
  • 112
Eugene
  • 117,005
  • 15
  • 201
  • 306
  • I had already added the guava module earlier and also registered it in my dropwizard application during initialize phase. But that did not help. I tried again post your recommendation but I I am getting the same issue. Jackson isn't able to convert the Immutable list to a corresponding Java collection I suppose. Not sure how to fix this. – serah Jul 18 '17 at 08:59
  • 1
    @alice: Are you certain that your application only contains one `ObjectMapper` instance? Could it be that you're actually receiving a different one that the one you configured? – Henrik Aasted Sørensen Aug 02 '17 at 08:14