我正在尝试使用我的rest控制器创建一个补丁。我不断出错。我希望补丁能够成功运行。
我尝试了使用json-patch的各种方法。
@PatchMapping(value="/bmwsales/updatescanner/{id}",
consumes="application/json-patch+json")
public ResponseEntity<Void>
updateVehicleTagAndroid(@PathVariable(value="id") Integer id,@RequestBody
JsonPatch patchDoc) {
Bmwsales
vehicle=bmwService.getVin(id).orElseThrow(ResourceNotFoundException::new);
BmwsalesUpdate bmwUpdate=mapper.INSTANCE.asInput(vehicle);
Bmwsales bmwUpdatePatched=patchHelp.patch(patchDoc, vehicle,
Bmwsales.class);
return ResponseEntity.noContent().build();
PatchHelp
@Component
public class PatchHelp {
private ObjectMapper oMapper;
public PatchHelp(ObjectMapper opMapper){
this.oMapper=oMapper;
}
public <T> T patch(JsonPatch patch, T targetBean, Class<T> beanClass){
JsonStructure target=oMapper.convertValue(targetBean, JsonStructure.class);
JsonValue patched=patch.apply(target);
return oMapper.convertValue(patched, beanClass);
}
错误消息是: java.lang.NullPointerException:空 在com.principleauto.rfid.util.PatchHelp.patch(PatchHelp.java:37)
com.principleauto.rfid.controller.BmwsalesController.updateVehicleTagAndroid(BmwsalesController.java:221) 在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处 在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在java.lang.reflect.Method.invoke(Method.java:498)
我不知道我在想什么........