Improve Kryo Codec for registrations
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
* Copyright 2015-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -39,8 +39,9 @@ public class CompositeCodecTests {
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
Map<Class<?>, Codec> codecs = new HashMap<Class<?>, Codec>();
|
||||
this.codec = new CompositeCodec(codecs, new PojoCodec());
|
||||
Map<Class<?>, Codec> codecs = new HashMap<>();
|
||||
this.codec = new CompositeCodec(codecs, new PojoCodec(
|
||||
new KryoClassListRegistrar(SomeClassWithNoDefaultConstructors.class)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
* Copyright 2015-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -66,7 +66,7 @@ public class KryoCodecTests {
|
||||
|
||||
@Test
|
||||
public void testPojoSerialization() throws IOException {
|
||||
PojoCodec codec = new PojoCodec();
|
||||
PojoCodec codec = new PojoCodec(new KryoClassListRegistrar(SomeClassWithNoDefaultConstructors.class));
|
||||
SomeClassWithNoDefaultConstructors foo = new SomeClassWithNoDefaultConstructors("foo", 123);
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
codec.encode(foo, bos);
|
||||
@@ -101,12 +101,12 @@ public class KryoCodecTests {
|
||||
|
||||
@Test
|
||||
public void testMapSerialization() throws IOException {
|
||||
PojoCodec codec = new PojoCodec();
|
||||
PojoCodec codec = new PojoCodec(new KryoClassListRegistrar(HashMap.class));
|
||||
Map<String, Integer> map = new HashMap<>();
|
||||
map.put("one", 1);
|
||||
map.put("two", 2);
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
codec.encode(map, bos);
|
||||
codec.encode(map, bos);4
|
||||
Map<?, ?> m2 = (Map<?, ?>) codec.decode(bos.toByteArray(), HashMap.class);
|
||||
assertThat(m2.size()).isEqualTo(2);
|
||||
assertThat(m2.get("one")).isEqualTo(1);
|
||||
@@ -115,7 +115,7 @@ public class KryoCodecTests {
|
||||
|
||||
@Test
|
||||
public void testComplexObjectSerialization() throws IOException {
|
||||
PojoCodec codec = new PojoCodec();
|
||||
PojoCodec codec = new PojoCodec(new KryoClassListRegistrar(Foo.class));
|
||||
Foo foo = new Foo();
|
||||
foo.put("one", 1);
|
||||
foo.put("two", 2);
|
||||
|
||||
Reference in New Issue
Block a user