Skip to content
This repository was archived by the owner on Feb 24, 2026. It is now read-only.

Commit 10f0a87

Browse files
authored
refact(common): rename jsonutil to avoid conflicts with server (#136)
fix https://github.com/apache/incubator-hugegraph/actions/runs/7082354080/job/19273001614?pr=2365 Also add some comment for it
1 parent 8c93652 commit 10f0a87

File tree

2 files changed

+44
-12
lines changed

2 files changed

+44
-12
lines changed

hugegraph-common/src/main/java/org/apache/hugegraph/rest/AbstractRestClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import javax.net.ssl.X509TrustManager;
3838

3939
import org.apache.commons.lang3.StringUtils;
40-
import org.apache.hugegraph.util.JsonUtil;
40+
import org.apache.hugegraph.util.JsonUtilCommon;
4141
import org.jetbrains.annotations.NotNull;
4242

4343
import com.google.common.collect.ImmutableMap;
@@ -128,7 +128,7 @@ private static RequestBody buildRequestBody(Object body, RestHeaders headers) {
128128
if (body == null) {
129129
bodyContent = "{}";
130130
} else {
131-
bodyContent = JsonUtil.toJson(body);
131+
bodyContent = JsonUtilCommon.toJson(body);
132132
}
133133
} else {
134134
bodyContent = String.valueOf(body);

hugegraph-common/src/main/java/org/apache/hugegraph/util/JsonUtil.java renamed to hugegraph-common/src/main/java/org/apache/hugegraph/util/JsonUtilCommon.java

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,46 +17,78 @@
1717

1818
package org.apache.hugegraph.util;
1919

20+
import java.io.IOException;
21+
22+
import org.apache.hugegraph.rest.SerializeException;
23+
2024
import com.fasterxml.jackson.core.JsonProcessingException;
2125
import com.fasterxml.jackson.databind.JsonNode;
2226
import com.fasterxml.jackson.databind.Module;
2327
import com.fasterxml.jackson.databind.ObjectMapper;
24-
import org.apache.hugegraph.rest.SerializeException;
25-
26-
import java.io.IOException;
2728

28-
public final class JsonUtil {
29+
/**
30+
* Utility class for JSON operations.
31+
*/
32+
public final class JsonUtilCommon {
2933

34+
/**
35+
* ObjectMapper instance used for JSON operations.
36+
*/
3037
private static final ObjectMapper MAPPER = new ObjectMapper();
3138

39+
/**
40+
* Registers a module with the ObjectMapper.
41+
*
42+
* @param module the module to register
43+
*/
3244
public static void registerModule(Module module) {
3345
MAPPER.registerModule(module);
3446
}
3547

48+
/**
49+
* Converts an object to a JSON string.
50+
*
51+
* @param object the object to convert
52+
* @return the JSON string representation of the object
53+
* @throws SerializeException if the object cannot be serialized
54+
*/
3655
public static String toJson(Object object) {
3756
try {
3857
return MAPPER.writeValueAsString(object);
3958
} catch (JsonProcessingException e) {
40-
throw new SerializeException("Failed to serialize object '%s'",
41-
e, object);
59+
throw new SerializeException("Failed to serialize object '%s'", e, object);
4260
}
4361
}
4462

63+
/**
64+
* Converts a JSON string to an object of the specified class.
65+
*
66+
* @param json the JSON string
67+
* @param clazz the class of the object
68+
* @return the object represented by the JSON string
69+
* @throws SerializeException if the JSON string cannot be deserialized
70+
*/
4571
public static <T> T fromJson(String json, Class<T> clazz) {
4672
try {
4773
return MAPPER.readValue(json, clazz);
4874
} catch (IOException e) {
49-
throw new SerializeException("Failed to deserialize json '%s'",
50-
e, json);
75+
throw new SerializeException("Failed to deserialize json '%s'", e, json);
5176
}
5277
}
5378

79+
/**
80+
* Converts a JsonNode to an object of the specified class.
81+
*
82+
* @param node the JsonNode
83+
* @param clazz the class of the object
84+
* @return the object represented by the JsonNode
85+
* @throws SerializeException if the JsonNode cannot be deserialized
86+
*/
5487
public static <T> T convertValue(JsonNode node, Class<T> clazz) {
5588
try {
5689
return MAPPER.convertValue(node, clazz);
5790
} catch (IllegalArgumentException e) {
58-
throw new SerializeException("Failed to deserialize json node '%s'",
59-
e, node);
91+
throw new SerializeException("Failed to deserialize json node '%s'", e, node);
6092
}
6193
}
6294
}

0 commit comments

Comments
 (0)