diff --git a/src/main/java/com/andrewlalis/record_net/IOUtil.java b/src/main/java/com/andrewlalis/record_net/IOUtil.java index d7f3a10..eb40e1a 100644 --- a/src/main/java/com/andrewlalis/record_net/IOUtil.java +++ b/src/main/java/com/andrewlalis/record_net/IOUtil.java @@ -3,6 +3,7 @@ package com.andrewlalis.record_net; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; +import java.util.Set; import java.util.UUID; /** @@ -12,6 +13,12 @@ import java.util.UUID; public final class IOUtil { private IOUtil() {} + public static boolean isPrimitiveOrWrapper(Class type) { + final Set> types = Set.of(Byte.class, Short.class, Integer.class, Character.class, Float.class, Double.class, Long.class, Boolean.class); + return type.isPrimitive() || types.contains(type); + + } + public static Object readPrimitive(Class type, DataInputStream dIn) throws IOException { if (type.equals(Integer.class) || type.equals(int.class)) return dIn.readInt(); if (type.equals(Short.class) || type.equals(short.class)) return dIn.readShort(); diff --git a/src/main/java/com/andrewlalis/record_net/RecordMappedSerializer.java b/src/main/java/com/andrewlalis/record_net/RecordMappedSerializer.java index a550045..9ac5156 100644 --- a/src/main/java/com/andrewlalis/record_net/RecordMappedSerializer.java +++ b/src/main/java/com/andrewlalis/record_net/RecordMappedSerializer.java @@ -89,7 +89,7 @@ public class RecordMappedSerializer implements RecordSerializer { if (type.equals(String.class)) { return IOUtil.readString(dIn); } - if (type.isPrimitive()) { + if (IOUtil.isPrimitiveOrWrapper(type)) { return IOUtil.readPrimitive(type, dIn); } throw new UnsupportedMessageTypeException(type); @@ -132,7 +132,7 @@ public class RecordMappedSerializer implements RecordSerializer { IOUtil.writeUUID((UUID) obj, dOut); } else if (type.equals(String.class)) { IOUtil.writeString((String) obj, dOut); - } else if (type.isPrimitive()) { + } else if (IOUtil.isPrimitiveOrWrapper(type)) { IOUtil.writePrimitive(obj, dOut); } else { throw new UnsupportedMessageTypeException(type);