From e07cbda769c55805793c13a8d52aaef0c191d69c Mon Sep 17 00:00:00 2001 From: r-ca Date: Sun, 14 Jan 2024 12:48:54 +0900 Subject: [PATCH] =?UTF-8?q?toJson=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nem/lacerta/vcs/internal/JsonUtils.java | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 vcs/src/main/java/one/nem/lacerta/vcs/internal/JsonUtils.java diff --git a/vcs/src/main/java/one/nem/lacerta/vcs/internal/JsonUtils.java b/vcs/src/main/java/one/nem/lacerta/vcs/internal/JsonUtils.java new file mode 100644 index 00000000..db9ac496 --- /dev/null +++ b/vcs/src/main/java/one/nem/lacerta/vcs/internal/JsonUtils.java @@ -0,0 +1,55 @@ +package one.nem.lacerta.vcs.internal; + +import android.provider.ContactsContract; + +import one.nem.lacerta.vcs.ActionType; +import one.nem.lacerta.vcs.model.action.DeletePage; +import one.nem.lacerta.vcs.model.action.InsertPage; +import one.nem.lacerta.vcs.model.action.UpdatePage; +import one.nem.lacerta.vcs.model.action.common.ActionBase; + +import com.fasterxml.jackson.databind.ObjectMapper; + +public class JsonUtils { + + // TODO-rca: Injectionで実装しなおす + + // Public methods + + public static String toJson(Object object) { + ActionBase converted; + if (object == null) { + return null; + } else if (object instanceof ActionBase) { + ObjectMapper mapper = new ObjectMapper(); + switch (((ActionBase) object).getActionType()) { + case INSERT_PAGE: + converted = (InsertPage) object; + break; + case UPDATE_PAGE: + converted = (UpdatePage) object; + break; + case DELETE_PAGE: + converted = (DeletePage) object; + break; + default: + throw new IllegalArgumentException("Unknown action type"); + } + try { + return mapper.writeValueAsString(converted); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + throw new IllegalArgumentException("Unknown object type"); + } + + + public static T fromJson(String json, ActionType actionType, Class clazz) { + return null; + } + + // Internal methods + + +}