-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: extract opengemini common module (#13)
Signed-off-by: ZhangJian He <[email protected]>
- Loading branch information
ZhangJian He
authored
Feb 14, 2024
1 parent
ef91d1b
commit b2e93a9
Showing
12 changed files
with
100 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>io.opengemini</groupId> | ||
<artifactId>opengemini-client-parent</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>opengemini-client-common</artifactId> | ||
|
||
</project> |
57 changes: 57 additions & 0 deletions
57
opengemini-client-common/src/main/java/io/opengemini/client/common/JacksonService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package io.opengemini.client.common; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import com.fasterxml.jackson.databind.DeserializationFeature; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.node.ArrayNode; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
|
||
import java.util.List; | ||
|
||
public class JacksonService { | ||
private static final ObjectMapper MAPPER = new ObjectMapper(); | ||
|
||
static { | ||
MAPPER.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, false); | ||
MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); | ||
} | ||
|
||
public static String toJson(Object o) throws JsonProcessingException { | ||
return MAPPER.writeValueAsString(o); | ||
} | ||
|
||
public static <T> T toObject(String json, Class<T> type) throws JsonProcessingException { | ||
if (json == null || json.isEmpty()) { | ||
return null; | ||
} | ||
return MAPPER.readValue(json, type); | ||
} | ||
|
||
public static <T> T toRefer(String json, TypeReference<T> ref) throws JsonProcessingException { | ||
if (json == null || json.isEmpty()) { | ||
return null; | ||
} | ||
return MAPPER.readValue(json, ref); | ||
} | ||
|
||
public static <T> List<T> toList(String json, TypeReference<List<T>> typeRef) throws JsonProcessingException { | ||
if (json == null || json.isEmpty()) { | ||
return List.of(); | ||
} | ||
return MAPPER.readValue(json, typeRef); | ||
} | ||
|
||
public static JsonNode toJsonNode(String json) throws JsonProcessingException { | ||
return MAPPER.readTree(json); | ||
} | ||
|
||
public static ObjectNode createObjectNode() { | ||
return MAPPER.createObjectNode(); | ||
} | ||
|
||
public static ArrayNode createArrayNode() { | ||
return MAPPER.createArrayNode(); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
opengemini-client-common/src/main/java/io/opengemini/client/common/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package io.opengemini.client.common; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 0 additions & 11 deletions
11
opengemini-client-jdk/src/main/java/io/opengemini/client/jdk/common/OpenGeminiCommon.java
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
opengemini-client-jdk/src/main/java/io/opengemini/client/jdk/common/package-info.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters