diff --git a/jackson/src/main/java/nl/sanderhautvast/contiguous/ListSerializer.java b/jackson/src/main/java/nl/sanderhautvast/contiguous/ListSerializer.java index 70de235..33a7407 100644 --- a/jackson/src/main/java/nl/sanderhautvast/contiguous/ListSerializer.java +++ b/jackson/src/main/java/nl/sanderhautvast/contiguous/ListSerializer.java @@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.ser.std.StdSerializer; import java.io.IOException; +import java.util.ArrayList; public class ListSerializer extends StdSerializer> { @@ -17,7 +18,6 @@ public class ListSerializer extends StdSerializer> { public void serialize( ContiguousList value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { - // value. // jgen.writeStartObject(); diff --git a/lib/src/main/java/nl/sanderhautvast/contiguous/BigDecimalHandler.java b/lib/src/main/java/nl/sanderhautvast/contiguous/BigDecimalHandler.java index f9ef444..e2a92b8 100644 --- a/lib/src/main/java/nl/sanderhautvast/contiguous/BigDecimalHandler.java +++ b/lib/src/main/java/nl/sanderhautvast/contiguous/BigDecimalHandler.java @@ -14,7 +14,7 @@ class BigDecimalHandler extends BuiltinTypeHandler { } @Override - public Object transform(Object value) { + public Object cast(Object value) { return new BigDecimal((String) value); } } diff --git a/lib/src/main/java/nl/sanderhautvast/contiguous/BigIntegerHandler.java b/lib/src/main/java/nl/sanderhautvast/contiguous/BigIntegerHandler.java index 1d19d74..09823b8 100644 --- a/lib/src/main/java/nl/sanderhautvast/contiguous/BigIntegerHandler.java +++ b/lib/src/main/java/nl/sanderhautvast/contiguous/BigIntegerHandler.java @@ -14,7 +14,7 @@ class BigIntegerHandler extends BuiltinTypeHandler { } @Override - public Object transform(Object value) { + public Object cast(Object value) { return new BigInteger((String) value); } } diff --git a/lib/src/main/java/nl/sanderhautvast/contiguous/BuiltinTypeHandler.java b/lib/src/main/java/nl/sanderhautvast/contiguous/BuiltinTypeHandler.java index 12e847d..95f51a9 100644 --- a/lib/src/main/java/nl/sanderhautvast/contiguous/BuiltinTypeHandler.java +++ b/lib/src/main/java/nl/sanderhautvast/contiguous/BuiltinTypeHandler.java @@ -54,7 +54,7 @@ public abstract class BuiltinTypeHandler extends TypeHandler { */ public void setValue(Object instance, Object value) { try { - setter.invokeWithArguments(instance, transform(value)); + setter.invokeWithArguments(instance, cast(value)); } catch (Throwable e) { throw new IllegalStateException(e); } @@ -64,13 +64,13 @@ public abstract class BuiltinTypeHandler extends TypeHandler { * Certain types can easily be stored as another known type, for instance * a BigDecimal can be stored as a String. *

- * The {@link BuiltinTypeHandler} for BigDecimal would in that case be responsible for turning the String - * into a BigDecimal. It can do that by overriding this method + * The {@link BuiltinTypeHandler} for BigDecimal would in that case be responsible for casting the String + * into a BigDecimal. It can do that by overriding this method. * * @param value raw value to transform to the desired output type * @return the transformed object */ - public Object transform(Object value) { + public Object cast(Object value) { return value; } } diff --git a/lib/src/main/java/nl/sanderhautvast/contiguous/ByteHandler.java b/lib/src/main/java/nl/sanderhautvast/contiguous/ByteHandler.java index 0ad0afe..d578376 100644 --- a/lib/src/main/java/nl/sanderhautvast/contiguous/ByteHandler.java +++ b/lib/src/main/java/nl/sanderhautvast/contiguous/ByteHandler.java @@ -22,7 +22,7 @@ class ByteHandler extends BuiltinTypeHandler { } @Override - public Object transform(Object value) { + public Object cast(Object value) { if (value instanceof Long) { return ((Long) value).byteValue(); } diff --git a/lib/src/main/java/nl/sanderhautvast/contiguous/IntegerHandler.java b/lib/src/main/java/nl/sanderhautvast/contiguous/IntegerHandler.java index 1481605..996be7f 100644 --- a/lib/src/main/java/nl/sanderhautvast/contiguous/IntegerHandler.java +++ b/lib/src/main/java/nl/sanderhautvast/contiguous/IntegerHandler.java @@ -22,7 +22,7 @@ class IntegerHandler extends BuiltinTypeHandler { } @Override - public Object transform(Object value) { + public Object cast(Object value) { // could be Long (raw value) // or Integer when it's a property with known type if (value instanceof Long) { diff --git a/lib/src/main/java/nl/sanderhautvast/contiguous/ShortHandler.java b/lib/src/main/java/nl/sanderhautvast/contiguous/ShortHandler.java index d81d20b..d128efb 100644 --- a/lib/src/main/java/nl/sanderhautvast/contiguous/ShortHandler.java +++ b/lib/src/main/java/nl/sanderhautvast/contiguous/ShortHandler.java @@ -18,7 +18,7 @@ class ShortHandler extends BuiltinTypeHandler { } @Override - public Object transform(Object value) { + public Object cast(Object value) { if (value instanceof Long) { return ((Long) value).shortValue(); } diff --git a/lib/src/main/java/nl/sanderhautvast/contiguous/TypeHandler.java b/lib/src/main/java/nl/sanderhautvast/contiguous/TypeHandler.java index 54f5f36..08a8162 100644 --- a/lib/src/main/java/nl/sanderhautvast/contiguous/TypeHandler.java +++ b/lib/src/main/java/nl/sanderhautvast/contiguous/TypeHandler.java @@ -2,11 +2,13 @@ package nl.sanderhautvast.contiguous; import java.lang.invoke.MethodHandle; -/* - * ok, sorry +/** + * Abstract basertype over handlers for 'primitives' (ie. long, but also Long, + * String..=> built-in types) and compound types (your own). * - * I needed to abstract over handlers for 'primitives' (ie. long, but also Long, String..=> built-in types) and compound types (your own) - * So this is the common ancestor. The respective functions are completely different. + * Common ancestor primarily to iterator over properties of any type. + * The respective functions are completely different though, and we need `instanceof` to check for the + * actual type. (Rust enums!) */ public abstract class TypeHandler {