0

I am using json patch 1.13 version to apply patch on my json payload .

This is the POM Entry using for json patch

<dependency>
  <groupId>com.github.java-json-tools</groupId>
  <artifactId>json-patch</artifactId>
  <version>1.13</version>
</dependency>

The existing payload have value like

{
 "expirationDate": "2022-05-15T01:59:59"
}

I am applying the patch with below patch operation, . This is to update the value with new date .

[
{
    "op": "replace",
    "path": "/expirationDate",
    "value": "2023-05-15T02:59:59"
}
]

But after applying the patch the new object have differently formatted Date value like

Java code
JsonNode patched = patch.apply(objectMapper.convertValue(targetCustomer, JsonNode.class));
return objectMapper.treeToValue(patched, Customer.class);

Output
expirationDate=Mon May 15 01:59:59 EDT 2023

Expected Output
expirationDate: "2023-05-15T01:59:59"

Any reason its changing the format or how i can fix this.
VKP
  • 589
  • 1
  • 8
  • 34
  • 2
    What is `patch`? What JSON libraries are you using? Please provide a minimal reproducible example as explained in the help center page: http://stackoverflow.com/help/minimal-reproducible-example – aled May 16 '23 at 15:50
  • 2
    Where exactly is the "output" coming from? Is it possible that you're actually seeing the result of calling `toString()` on a `java.util.Date`? (In which case it's got nothing to do with the patch.) – Jon Skeet May 16 '23 at 15:50
  • The formatted date i am seeing on patched object. I can see the formatted date when i am calling toString on that Object. – VKP May 16 '23 at 16:01
  • In another way to explain , say i am applying same date on patch like [ { "op": "replace", "path": "/expirationDate", "value": "2022-05-15T02:59:59" } ] So the existing and new object have same value . But if i call existingObject.equals(newpatchedObjt) should say its same . But in this case because of the Date format difference its saying the objects are not equal. – VKP May 16 '23 at 16:05

0 Answers0