rename method
This commit is contained in:
parent
1241c64d3e
commit
4d1ae5acf4
8 changed files with 16 additions and 14 deletions
|
|
@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.SerializerProvider;
|
||||||
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
|
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class ListSerializer<E> extends StdSerializer<ContiguousList<E>> {
|
public class ListSerializer<E> extends StdSerializer<ContiguousList<E>> {
|
||||||
|
|
||||||
|
|
@ -17,7 +18,6 @@ public class ListSerializer<E> extends StdSerializer<ContiguousList<E>> {
|
||||||
public void serialize(
|
public void serialize(
|
||||||
ContiguousList<E> value, JsonGenerator jgen, SerializerProvider provider)
|
ContiguousList<E> value, JsonGenerator jgen, SerializerProvider provider)
|
||||||
throws IOException, JsonProcessingException {
|
throws IOException, JsonProcessingException {
|
||||||
|
|
||||||
// value.
|
// value.
|
||||||
|
|
||||||
// jgen.writeStartObject();
|
// jgen.writeStartObject();
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ class BigDecimalHandler extends BuiltinTypeHandler<BigDecimal> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object transform(Object value) {
|
public Object cast(Object value) {
|
||||||
return new BigDecimal((String) value);
|
return new BigDecimal((String) value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ class BigIntegerHandler extends BuiltinTypeHandler<BigInteger> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object transform(Object value) {
|
public Object cast(Object value) {
|
||||||
return new BigInteger((String) value);
|
return new BigInteger((String) value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ public abstract class BuiltinTypeHandler<T> extends TypeHandler {
|
||||||
*/
|
*/
|
||||||
public void setValue(Object instance, Object value) {
|
public void setValue(Object instance, Object value) {
|
||||||
try {
|
try {
|
||||||
setter.invokeWithArguments(instance, transform(value));
|
setter.invokeWithArguments(instance, cast(value));
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
throw new IllegalStateException(e);
|
throw new IllegalStateException(e);
|
||||||
}
|
}
|
||||||
|
|
@ -64,13 +64,13 @@ public abstract class BuiltinTypeHandler<T> extends TypeHandler {
|
||||||
* Certain types can easily be stored as another known type, for instance
|
* Certain types can easily be stored as another known type, for instance
|
||||||
* a BigDecimal can be stored as a String.
|
* a BigDecimal can be stored as a String.
|
||||||
* <p>
|
* <p>
|
||||||
* The {@link BuiltinTypeHandler} for BigDecimal would in that case be responsible for turning the String
|
* 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
|
* into a BigDecimal. It can do that by overriding this method.
|
||||||
*
|
*
|
||||||
* @param value raw value to transform to the desired output type
|
* @param value raw value to transform to the desired output type
|
||||||
* @return the transformed object
|
* @return the transformed object
|
||||||
*/
|
*/
|
||||||
public Object transform(Object value) {
|
public Object cast(Object value) {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ class ByteHandler extends BuiltinTypeHandler<Byte> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object transform(Object value) {
|
public Object cast(Object value) {
|
||||||
if (value instanceof Long) {
|
if (value instanceof Long) {
|
||||||
return ((Long) value).byteValue();
|
return ((Long) value).byteValue();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ class IntegerHandler extends BuiltinTypeHandler<Integer> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object transform(Object value) {
|
public Object cast(Object value) {
|
||||||
// could be Long (raw value)
|
// could be Long (raw value)
|
||||||
// or Integer when it's a property with known type
|
// or Integer when it's a property with known type
|
||||||
if (value instanceof Long) {
|
if (value instanceof Long) {
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ class ShortHandler extends BuiltinTypeHandler<Short> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object transform(Object value) {
|
public Object cast(Object value) {
|
||||||
if (value instanceof Long) {
|
if (value instanceof Long) {
|
||||||
return ((Long) value).shortValue();
|
return ((Long) value).shortValue();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,13 @@ package nl.sanderhautvast.contiguous;
|
||||||
|
|
||||||
import java.lang.invoke.MethodHandle;
|
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)
|
* Common ancestor primarily to iterator over properties of any type.
|
||||||
* So this is the common ancestor. The respective functions are completely different.
|
* The respective functions are completely different though, and we need `instanceof` to check for the
|
||||||
|
* actual type. (Rust enums!)
|
||||||
*/
|
*/
|
||||||
public abstract class TypeHandler {
|
public abstract class TypeHandler {
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue