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


##########
hugegraph-common/src/main/java/org/apache/hugegraph/rest/AbstractRestClient.java:
##########
@@ -396,17 +398,35 @@ 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
+     */
+    public static 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) {

Review Comment:
   and here the judge is redundant, change it to `xx != null`, I address them 
in PR #115 



##########
hugegraph-common/src/main/java/org/apache/hugegraph/rest/AbstractRestClient.java:
##########
@@ -396,17 +398,35 @@ 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
+     */
+    public static MediaType parseCustomContentType(MultivaluedMap<String, 
Object> headers) {
+        String customContentType = null;
+        if (MapUtils.isNotEmpty(headers) && headers.get("Content-Type") != 
null) {
+            Object contentTypeObj = headers.get("Content-Type");

Review Comment:
   seems we don't need `Object` here, just use `List<?>`



-- 
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