最后我自己找到了解决办法。
我重写了U1代码
var h = value === null?'null':(v === ''?'empty-string':(v === undefined?'undefined':null));
if (h != null) {
u1.setRequestHeader('X-empty-body-interpret-as', h);
}
(我知道你们都在想什么:嘿,你们违反了RFC 6648,但我现在不在乎)
在控制器中,我像这样读取标题:
@RequestMapping(value="java/packagename", method = RequestMethod.POST)
public ResponseEntity<Object> updatePackage(@RequestBody(required=false) String entityPackageNew, HttpServletRequest request) {
String interpretNullAs = request.getHeader("X-empty-body-interpret-as");
DP databaseMavenRevelation = entityManager.find(DP.class, databaseMavenRevelationId);
if (entityPackageNew == null) {
switch (interpretNullAs) {
case "empty-string":
databaseMavenRevelation.setEntityPackage("");
break;
case "null":
case "undefined":
databaseMavenRevelation.setEntityPackage(null);
break;
}
} else {
databaseMavenRevelation.setEntityPackage(entityPackageNew);
}
entityManager.persist(databaseMavenRevelation);
return new ResponseEntity<>(HttpStatus.OK);
}