Uploaded image for project: 'Spring Data REST'
  1. Spring Data REST
  2. DATAREST-1338

JSON patch doesn't update single Map's values

    Details

      Description

      Steps to reproduce:

      //Here is my object
      public class Book {
          public String author;
          public String ISBN;
          public Map<String, String> characters;
      }
      
      // Here I create a simple instance of the object
      Book myBook = new Book();
      myBook.author = "Me"
      myBook.ISBN = "1234567890"
      myBook.characters = new HashMap<>();
      myBook.characters.put("protagonist", "Pinco");
      myBook.characters.put("antagonist", "Pallo");
      

      Here I create JSON patches

      // Here the type of operations that work
      [
          {"op": "replace", "path": "/author", "value": "NewAuthor"},
          {"op": "replace", "path": "/ISBN", "value": 0987654321 },
      ]
      
      // I can also modify completely the Map if I want
      [
          {"op": "replace", "path": "/characters", "value": {"protagonist": "Pallo", "antagonist": "Pinco"} }
      ]
        

      Here the kind of operations that I would expect to work but do not work

      // But I can't update a single value in the map 
      [ 
      {"op": "replace", "path": "/characters/protagonist", "value": "Pallo" }, {"op": "replace", "path": "/characters/antagonist", "value": "Pinco" } 
      ] 
      
      // I've also tried weird stuff, but doesn't work 
      [ {"op": "replace", "path": "/characters[antagonist]", "value": "Pinco"} ]  

       
      Expected result:
      I would expect the replace operation on the nested map to work by checking the key.
       
      I think the issue is in the path->SpEL conversion, as the nested fields are automatically converted to properties updates.
       

        Attachments

          Activity

            People

            • Assignee:
              olivergierke Oliver Drotbohm
              Reporter:
              Kerruba Luca Cherubin
              Last updater:
              Christoph Strobl
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: