Skip to content

Cache Serialization serializes empty contents #90

@wlfbck

Description

@wlfbck

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>

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions