diff --git a/pom.xml b/pom.xml index 888816767..47f30cb86 100755 --- a/pom.xml +++ b/pom.xml @@ -47,7 +47,7 @@ net.openhft chronicle-bom pom - 1.12.10 + 1.12.14-SNAPSHOT import @@ -64,7 +64,6 @@ net.openhft chronicle-values - 1.0.7-alpha @@ -95,7 +94,6 @@ net.openhft chronicle-algorithms - 1.1.7 diff --git a/src/main/java/net/openhft/chronicle/hash/serialization/impl/InstanceCreatingMarshaller.java b/src/main/java/net/openhft/chronicle/hash/serialization/impl/InstanceCreatingMarshaller.java index 1042e818e..954135260 100644 --- a/src/main/java/net/openhft/chronicle/hash/serialization/impl/InstanceCreatingMarshaller.java +++ b/src/main/java/net/openhft/chronicle/hash/serialization/impl/InstanceCreatingMarshaller.java @@ -16,6 +16,7 @@ package net.openhft.chronicle.hash.serialization.impl; +import net.openhft.chronicle.core.util.ObjectUtils; import net.openhft.chronicle.hash.Data; import net.openhft.chronicle.hash.serialization.DataAccess; import net.openhft.chronicle.hash.serialization.SizedReader; @@ -62,8 +63,8 @@ public abstract class InstanceCreatingMarshaller implements Marshallable { */ protected T createInstance() { try { - return tClass.newInstance(); - } catch (InstantiationException | IllegalAccessException e) { + return ObjectUtils.newInstance(tClass); + } catch (Exception e) { throw new IllegalStateException("Some of default marshallers, chosen for the type\n" + tClass + " by default, delegates to \n" + this.getClass().getName() + " which assumes the type has a public no-arg\n" + diff --git a/src/test/java/net/openhft/chronicle/map/BytesMarshallableValueTest.java b/src/test/java/net/openhft/chronicle/map/BytesMarshallableValueTest.java index 48da84689..15e96d2a5 100644 --- a/src/test/java/net/openhft/chronicle/map/BytesMarshallableValueTest.java +++ b/src/test/java/net/openhft/chronicle/map/BytesMarshallableValueTest.java @@ -16,7 +16,6 @@ package net.openhft.chronicle.map; -import net.openhft.chronicle.bytes.Bytes; import net.openhft.chronicle.bytes.BytesMarshallable; import org.junit.Assert; import org.junit.Test; @@ -37,7 +36,6 @@ public class BytesMarshallableValueTest { } public static class Value implements BytesMarshallable { - int x; String foo; @@ -46,19 +44,6 @@ public class BytesMarshallableValueTest { this.foo = foo; } - public Value() { - } - @Override - public void readMarshallable(Bytes bytes) { - x = bytes.readInt(); - foo = bytes.readUtf8(); - } - - @Override - public void writeMarshallable(Bytes bytes) { - bytes.writeInt(x); - bytes.writeUtf8(foo); - } } } diff --git a/src/test/java/net/openhft/chronicle/map/CHMUseCasesTest.java b/src/test/java/net/openhft/chronicle/map/CHMUseCasesTest.java index 94db8d75c..1cd06f306 100644 --- a/src/test/java/net/openhft/chronicle/map/CHMUseCasesTest.java +++ b/src/test/java/net/openhft/chronicle/map/CHMUseCasesTest.java @@ -17,8 +17,9 @@ package net.openhft.chronicle.map; import com.google.common.primitives.Chars; -import net.openhft.chronicle.bytes.Bytes; +import net.openhft.chronicle.bytes.BytesIn; import net.openhft.chronicle.bytes.BytesMarshallable; +import net.openhft.chronicle.bytes.BytesOut; import net.openhft.chronicle.core.Jvm; import net.openhft.chronicle.core.util.SerializableFunction; import net.openhft.chronicle.core.values.*; @@ -101,7 +102,7 @@ interface IData extends BytesMarshallable { } @Override - public void readMarshallable(@NotNull Bytes in) throws IllegalStateException { + public void readMarshallable(@NotNull BytesIn in) throws IllegalStateException { long magic = in.readLong(); if (magic != MAGIC) throw new AssertionError("Start " + Long.toHexString(magic)); @@ -113,7 +114,7 @@ interface IData extends BytesMarshallable { } @Override - public void writeMarshallable(@NotNull Bytes out) { + public void writeMarshallable(@NotNull BytesOut out) { out.writeLong(MAGIC); out.writeUTFΔ(text); out.writeInt(number); diff --git a/src/test/java/net/openhft/chronicle/map/SampleValues.java b/src/test/java/net/openhft/chronicle/map/SampleValues.java index 1623f884e..ff33c3879 100755 --- a/src/test/java/net/openhft/chronicle/map/SampleValues.java +++ b/src/test/java/net/openhft/chronicle/map/SampleValues.java @@ -15,7 +15,7 @@ */ package net.openhft.chronicle.map;/* - * Copyright 2013 peter.lawrey Lawrey + * Copyright 2013 peter.lawrey * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,8 +30,9 @@ package net.openhft.chronicle.map;/* * limitations under the License. */ -import net.openhft.chronicle.bytes.Bytes; +import net.openhft.chronicle.bytes.BytesIn; import net.openhft.chronicle.bytes.BytesMarshallable; +import net.openhft.chronicle.bytes.BytesOut; import org.jetbrains.annotations.NotNull; enum BuySell { @@ -54,7 +55,7 @@ public class SampleValues implements BytesMarshallable { long jj = 123456789; @Override - public void readMarshallable(@NotNull Bytes in) throws IllegalStateException { + public void readMarshallable(@NotNull BytesIn in) throws IllegalStateException { aa = in.readUtf8(); bb = in.readUtf8(); cc = (BuySell) in.readEnum(BuySell.class); @@ -68,7 +69,7 @@ public class SampleValues implements BytesMarshallable { } @Override - public void writeMarshallable(@NotNull Bytes out) { + public void writeMarshallable(@NotNull BytesOut out) { out.writeUtf8(aa); out.writeUtf8(bb); out.writeEnum(cc); diff --git a/src/test/java/net/openhft/chronicle/map/example/PointListSerializationTest.java b/src/test/java/net/openhft/chronicle/map/example/PointListSerializationTest.java index 90c8d436d..417d40018 100644 --- a/src/test/java/net/openhft/chronicle/map/example/PointListSerializationTest.java +++ b/src/test/java/net/openhft/chronicle/map/example/PointListSerializationTest.java @@ -17,7 +17,9 @@ package net.openhft.chronicle.map.example; import net.openhft.chronicle.bytes.Bytes; +import net.openhft.chronicle.bytes.BytesIn; import net.openhft.chronicle.bytes.BytesMarshallable; +import net.openhft.chronicle.bytes.BytesOut; import net.openhft.chronicle.hash.serialization.BytesReader; import net.openhft.chronicle.hash.serialization.BytesWriter; import net.openhft.chronicle.hash.serialization.impl.EnumMarshallable; @@ -31,9 +33,24 @@ import java.util.List; public class PointListSerializationTest { - static class A { - String str_; - List list_; + @Test + public void testComplexSerialization() { + try (ChronicleMap map = ChronicleMapBuilder + .of(String.class, A.class) + .valueMarshaller(AMarshaller.INSTANCE) + .entries(5) + .averageKeySize(4) + .averageValueSize(1000) + .create()) { + A obj_A = new A(); + obj_A.str_ = "a"; + obj_A.list_ = new ArrayList<>(); + B b = new B(); + b.str_ = "b"; + obj_A.list_.add(b); + map.put("KEY1", obj_A); + map.get("KEY1"); + } } enum AMarshaller implements BytesReader, BytesWriter, EnumMarshallable { @@ -86,37 +103,22 @@ public class PointListSerializationTest { } } + static class A { + String str_; + List list_; + } + static class B implements BytesMarshallable { String str_; @Override - public void readMarshallable(Bytes in) { + public void readMarshallable(BytesIn in) { str_ = in.readUtf8(); } @Override - public void writeMarshallable(Bytes out) { + public void writeMarshallable(BytesOut out) { out.writeUtf8(str_); } } - - @Test - public void testComplexSerialization() { - try (ChronicleMap map = ChronicleMapBuilder - .of(String.class, A.class) - .valueMarshaller(AMarshaller.INSTANCE) - .entries(5) - .averageKeySize(4) - .averageValueSize(1000) - .create()) { - A obj_A = new A(); - obj_A.str_ = "a"; - obj_A.list_ = new ArrayList<>(); - B b = new B(); - b.str_ = "b"; - obj_A.list_.add(b); - map.put("KEY1", obj_A); - map.get("KEY1"); - } - } }