Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-14498

MockMvcResultMatchers.jsonPath(String).value() should have a matching method to declare the expected type

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Complete
    • Affects Version/s: 4.2.5
    • Fix Version/s: 4.3.3, 5.0 M2
    • Component/s: Test
    • Labels:
      None
    • Last commented by a User:
      true

      Description

      Java Double instances will sometimes be converted from "12.0" to "12" in JSON based on rules/Jackson configuration.

      While reading the results back in testing, JsonPath will convert the "JSON number" to an Integer.

       String json = "{ \"value\" : 12}";
      
      Double expectedValue = 12.0;
      MockMvcResultMatchers.jsonPath("$.value").value(expectedValue) 
      ...
      ...
      ... expected:<java.lang.Double> but was:<java.lang.Integer>
      

      There should be an additional "value" method that accepts the target type for JsonPath to convert to.

      Double expectedValue = 12.0;
      MockMvcResultMatchers.jsonPath("$.value").value(expectedValue, Double.class) 
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              rstoya05-aop Rossen Stoyanchev
              Reporter:
              cmercer Chris Mercer
              Last updater:
              Spring Issuemaster
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Days since last comment:
                1 year, 25 weeks, 1 day ago