forked from loafle/openapi-generator-original
[Java][jersey2] Fix serializeToString (#6956)
* fix empty get body in serializeToString, add tests * add new file * fix serialize to better handle null string * update test comments
This commit is contained in:
@@ -791,9 +791,17 @@ public class ApiClient {
|
||||
} else {
|
||||
// We let jersey handle the serialization
|
||||
if (isBodyNullable) { // payload is nullable
|
||||
entity = Entity.entity(obj == null ? "null" : obj, contentType);
|
||||
if (obj instanceof String) {
|
||||
entity = Entity.entity(obj == null ? "null" : "\"" + ((String)obj).replaceAll("\"", Matcher.quoteReplacement("\\\"")) + "\"", contentType);
|
||||
} else {
|
||||
entity = Entity.entity(obj == null ? "null" : obj, contentType);
|
||||
}
|
||||
} else {
|
||||
entity = Entity.entity(obj == null ? "" : obj, contentType);
|
||||
if (obj instanceof String) {
|
||||
entity = Entity.entity(obj == null ? "" : "\"" + ((String)obj).replaceAll("\"", Matcher.quoteReplacement("\\\"")) + "\"", contentType);
|
||||
} else {
|
||||
entity = Entity.entity(obj == null ? "" : obj, contentType);
|
||||
}
|
||||
}
|
||||
}
|
||||
return entity;
|
||||
@@ -828,7 +836,7 @@ public class ApiClient {
|
||||
if (isBodyNullable) {
|
||||
return obj == null ? "null" : json.getMapper().writeValueAsString(obj);
|
||||
} else {
|
||||
return json.getMapper().writeValueAsString(obj);
|
||||
return obj == null ? "" : json.getMapper().writeValueAsString(obj);
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
|
||||
Reference in New Issue
Block a user