javeme commented on code in PR #113:
URL: 
https://github.com/apache/incubator-hugegraph-commons/pull/113#discussion_r1009501513


##########
hugegraph-common/src/main/java/org/apache/hugegraph/rest/AbstractRestClient.java:
##########
@@ -396,17 +398,37 @@ private Pair<Builder, Entity<?>> buildRequest(
          * because Entity.json() method will reset "content encoding =
          * null" that has been set up by headers before.
          */
+        MediaType customContentType = parseCustomContentType(headers);
         Entity<?> entity;
         if (encoding == null) {
-            entity = Entity.json(object);
+            entity = Entity.entity(object, customContentType);
         } else {
-            Variant variant = new Variant(MediaType.APPLICATION_JSON_TYPE,
+            Variant variant = new Variant(customContentType,
                                           (String) null, encoding);
             entity = Entity.entity(object, variant);
         }
         return Pair.of(builder, entity);
     }
 
+    /**
+     * parse user custom content-type, returns MediaType.APPLICATION_JSON_TYPE 
default.
+     * @param headers
+     * @return
+     */
+    private MediaType parseCustomContentType(MultivaluedMap<String, Object> 
headers) {

Review Comment:
   prefer to mark static



##########
hugegraph-common/src/main/java/org/apache/hugegraph/rest/AbstractRestClient.java:
##########
@@ -396,17 +398,37 @@ private Pair<Builder, Entity<?>> buildRequest(
          * because Entity.json() method will reset "content encoding =
          * null" that has been set up by headers before.
          */
+        MediaType customContentType = parseCustomContentType(headers);
         Entity<?> entity;
         if (encoding == null) {
-            entity = Entity.json(object);
+            entity = Entity.entity(object, customContentType);
         } else {
-            Variant variant = new Variant(MediaType.APPLICATION_JSON_TYPE,
+            Variant variant = new Variant(customContentType,
                                           (String) null, encoding);
             entity = Entity.entity(object, variant);
         }
         return Pair.of(builder, entity);
     }
 
+    /**
+     * parse user custom content-type, returns MediaType.APPLICATION_JSON_TYPE 
default.
+     * @param headers
+     * @return
+     */
+    private MediaType parseCustomContentType(MultivaluedMap<String, Object> 
headers) {
+        String customContentType = null;
+        if (MapUtils.isNotEmpty(headers) && headers.get("Content-Type") != 
null) {
+            Object contentTypeObj = headers.get("Content-Type");
+            if (contentTypeObj instanceof List) {
+                customContentType = ((List) contentTypeObj).get(0).toString();

Review Comment:
   use `List<?>` to avoid warning



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to