diff --git a/polydata-model/build.gradle b/polydata-model/build.gradle index 1db6dea..5f7a0e3 100644 --- a/polydata-model/build.gradle +++ b/polydata-model/build.gradle @@ -6,12 +6,6 @@ java { } dependencies { - - api( - "com.unidev.platform:unidev-common:$unidevPlatformVersion", - "com.unidev.platform:unidev-logger:$unidevPlatformVersion", - "com.unidev.platform:unidev-exception:$unidevPlatformVersion" - ) implementation "com.fasterxml.jackson.core:jackson-databind:$jacksonVersion" } \ No newline at end of file diff --git a/polydata-model/src/main/java/com/unidev/polydata4/domain/BasicPoly.java b/polydata-model/src/main/java/com/unidev/polydata4/domain/BasicPoly.java index d221677..4e364c9 100644 --- a/polydata-model/src/main/java/com/unidev/polydata4/domain/BasicPoly.java +++ b/polydata-model/src/main/java/com/unidev/polydata4/domain/BasicPoly.java @@ -2,8 +2,6 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.unidev.platform.common.DataTransform; -import com.unidev.platform.common.exception.UnidevRuntimeException; import lombok.Getter; import lombok.Setter; @@ -280,7 +278,7 @@ public

P getPolyList(String key, P defaultValue) { try { return (P) objectMapper.readValue(objectMapper.writeValueAsString(item), BasicPolyList.class); } catch (JsonProcessingException e) { - throw new UnidevRuntimeException(e); + throw new RuntimeException(e); } } return (P) item; @@ -311,7 +309,7 @@ public

P getPolyMap(String key, P defaultValue) { try { return (P) objectMapper.readValue(objectMapper.writeValueAsString(item), BasicPolyMap.class); } catch (JsonProcessingException e) { - throw new UnidevRuntimeException(e); + throw new RuntimeException(e); } } return (P) item; diff --git a/polydata-model/src/main/java/com/unidev/polydata4/domain/DataTransform.java b/polydata-model/src/main/java/com/unidev/polydata4/domain/DataTransform.java new file mode 100644 index 0000000..8f90469 --- /dev/null +++ b/polydata-model/src/main/java/com/unidev/polydata4/domain/DataTransform.java @@ -0,0 +1,34 @@ +package com.unidev.polydata4.domain; + +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Setter; + +import java.util.Map; +import java.util.Optional; + +@AllArgsConstructor +public class DataTransform { + + @Getter + @Setter + private final ObjectMapper objectMapper; + + public Optional toMap(Object object) { + try { + return Optional.ofNullable(objectMapper.readValue(objectMapper.writeValueAsBytes(object), Map.class)); + } catch (Exception e) { + return Optional.empty(); + } + } + + public Optional toObject(Object object, Class clazz) { + try { + return Optional.ofNullable(objectMapper.readValue(objectMapper.writeValueAsBytes(object), clazz)); + } catch (Exception e) { + return Optional.empty(); + } + } + +}