-
Notifications
You must be signed in to change notification settings - Fork 55
Closed
Description
I'm trying to serialize a Guava Cache<String,String>, so nothing fancy. But this seems to either fail (using default guava version 21.0) with an InvalidDefinitionException or return {}
(using guava 30.1.1-jre).
Here's my minimal example, i hope i'm just stupid and missing something here:
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.guava.GuavaModule;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
public class Testy {
public static void main(String[] args) throws Exception {
Testy test = new Testy();
}
private Cache<String, String> cache;
public Testy() throws Exception {
cache = CacheBuilder.newBuilder().build();
for(int i = 0; i < 10; i++) {
cache.put("abc"+i, "def");
}
ObjectMapper mapper = new ObjectMapper().registerModule(new GuavaModule());
System.out.println(mapper.writeValueAsString(cache));
System.out.println(cache.size());
}
}
My pom is minimal:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Test</groupId>
<artifactId>Test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.12.3</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>21.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-guava</artifactId>
<version>2.12.3</version>
</dependency>
</dependencies>
</project>