2

I'm using Spring-sync as an implementation of RFC 6902 (JSON Patch). The client side sends me a JsonNode representing the operations to apply on the server object.

My code is as following :

@PatchMapping(path = "/profile/{userId}")
public ResponseEntity<Void> patchUserProfile(@PathVariable Integer userId, @RequestBody JsonNode patchJsonNode) {

    JsonPatchMaker jsonPatchMaker = new JsonPatchMaker();
    Patch patch = jsonPatchMaker.fromJsonNode(patchJsonNode);

    UserProfileDto originalUserProfileDto = ...
    UserProfileDto patchedUser = patch.apply(originalUserProfileDto, UserProfileDto.class);

    userService.save(patchedUser);
    return ResponseEntity.status(HttpStatus.OK).body(null);
}

I have an unexpected Java ClassCastException telling me that the object cannot be cast to its same type !!?? How this can be possible ?

Below the stack trace :

java.lang.ClassCastException: com.roufid.api.dto.user.UserProfileDto cannot be cast to com.roufid.api.dto.user.UserProfileDto

Note : My class is loaded by the same classloader and it's Serializable.


I'm using :

  • Spring Sync : 1.0.0.M1
Radouane ROUFID
  • 10,595
  • 9
  • 42
  • 80
  • I guess it must have some kind of differences, as this happens during differences related to the serialization. The class is not loaded through a separate library/artifactory that includes a different version of the class itself? – vegaasen Feb 08 '17 at 08:36
  • It's a dto that I created myself in my spring boot project. The artifact was first included by eclipse using Eclipse workspae resolution. The problem still exists even when disabling this option. – Radouane ROUFID Feb 08 '17 at 08:44

0 Answers0