From 0d746deb4231b52f38a1a023d4c9815e5bb82918 Mon Sep 17 00:00:00 2001 From: Rhys <98863820+rhysdh540@users.noreply.github.com> Date: Fri, 17 May 2024 19:27:37 -0400 Subject: [PATCH] add missing primitives and rename reflection methods --- src/main/java/dev/nolij/zson/Zson.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/dev/nolij/zson/Zson.java b/src/main/java/dev/nolij/zson/Zson.java index c186ae9..6f1642f 100644 --- a/src/main/java/dev/nolij/zson/Zson.java +++ b/src/main/java/dev/nolij/zson/Zson.java @@ -129,7 +129,7 @@ public static String escape(String string, char escapeQuotes) { return result.toString(); } - public static Map fromObject(Object object) { + public static Map obj2Map(Object object) { Map map = Zson.object(); for (Field field : object.getClass().getDeclaredFields()) { if(Modifier.isStatic(field.getModifiers())) continue; @@ -144,7 +144,7 @@ public static Map fromObject(Object object) { return map; } - public static T toObject(Map map, Class type) { + public static T map2Obj(Map map, Class type) { try { T object = type.getDeclaredConstructor().newInstance(); for (Field field : type.getDeclaredFields()) { @@ -168,6 +168,9 @@ private static void setField(Field field, Object object, Object value) { case "int" -> field.setInt(object, (int) value); case "float" -> field.setFloat(object, (float) (double) value); case "double" -> field.setDouble(object, (double) value); + case "long" -> field.setLong(object, (long) value); + case "byte" -> field.setByte(object, (byte) (int) value); + case "char" -> field.setChar(object, (char) value); } } else { field.set(object, type.cast(value));