toJson実装

This commit is contained in:
r-ca 2024-01-14 12:48:54 +09:00
parent 80aeb8811b
commit e07cbda769
No known key found for this signature in database
GPG Key ID: 6A72911AC73464A9

View File

@ -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> T fromJson(String json, ActionType actionType, Class<T> clazz) {
return null;
}
// Internal methods
}