Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can EnumMapSerializer work with nested EnumMaps? #90

Open
whipit opened this issue Feb 27, 2018 · 1 comment
Open

How can EnumMapSerializer work with nested EnumMaps? #90

whipit opened this issue Feb 27, 2018 · 1 comment

Comments

@whipit
Copy link

whipit commented Feb 27, 2018

This is a feature request, not a bug.

If I have a nested map like so EnumMap<K1, EnumMap<K2, V>>, how can the EnumMapSerializer be modified to work with it?

At present, it doesn't quite work since the value of the top-level map is (de)serialized as an object instead of as another EnumMap.

Mr14huashao pushed a commit to Mr14huashao/kryo-serializers that referenced this issue Aug 28, 2020
Mr14huashao pushed a commit to Mr14huashao/kryo-serializers that referenced this issue Aug 28, 2020
Mr14huashao pushed a commit to Mr14huashao/kryo-serializers that referenced this issue Sep 22, 2020
@Mr14huashao
Copy link

PR can't pass CI, but test case :
@SuppressWarnings({"unchecked", "rawtypes"})
@test
public void testEnumMapNest() throws Exception {
_kryo.register(HashSet.class);
_kryo.register(Vipers.class);
_kryo.register(Colors.class);
_kryo.register(EnumMap.class, new EnumMapSerializer());

	final Set<String> mambaAka = new HashSet<String>();
	final Set<String> papaAka = new HashSet<>();
	mambaAka.add("Beatrix Kiddo");
	mambaAka.add("The Bride");
	papaAka.add("Good Job");
	papaAka.add("There is Great");

	_original.put(Vipers.BLACK_MAMBA, mambaAka);
	_original.put(Vipers.SIDEWINDER, papaAka);
	_newTempMap.put(Vipers.COPPERHEAD, _original);

	final File outputFile = File.createTempFile("input_file", "dat");
	try (final Output output = new Output(new FileOutputStream(outputFile))) {
		_kryo.writeObject(output, _newTempMap);
		output.flush();
		output.close();
		final Input input = new Input(new FileInputStream(outputFile));
		final EnumMap tEnumMap = _kryo.readObject(input, EnumMap.class);
		input.close();
		Assert.assertEquals(_newTempMap, tEnumMap);
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants