Oleksandr Verdiev
02/24/2025, 9:58 AM"yyyy-MM-dd'T'HH:mm:ssZ"
"yyyy-MM-dd'T'HH:mm:ss.SSZ"
"yyyy-MM-dd'T'HH:mm:ss.SSSZ"
...
"yyyy-MM-dd'T'HH:mm:ss.SSSSSSSSSZ"
I have tried these so far:
return new PactDslJsonBody()
.object("Data", looksLike()
.uuid("ConsentId")
.datetime("CreationDateTime", INSTANT_ISO_DATETIME_FORMAT, Instant.now())
// "yyyy-MM-dd'T'HH:mm:ss[.[SSSSSSSSS][SSSSSSSS][SSSSSSS][SSSSSS][SSSSS][SSSS][SSS][SS][S]]'Z'";
// static final String INSTANT_ISO_DATETIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSSSSSSSZ";
// static final String INSTANT_ISO_DATETIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss[.SSSSSSSSS]Z";
static final String INSTANT_ISO_DATETIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss(.SSSSSSSSS)?Z";Oleksandr Verdiev
03/07/2025, 10:01 AMOleksandr Verdiev
03/07/2025, 10:02 AMrholshausen
03/10/2025, 10:48 PMOleksandr Verdiev
03/11/2025, 9:11 AMrholshausen
03/11/2025, 10:29 PMrholshausen
03/11/2025, 10:31 PMthis would not present the real picture of Java's default serializationPact is used across multiple different languages. If we need to do that, we would also need to support the serialisation of instants in Go, .Net, JS, Ruby, Python, ..... how would that ever work?
Oleksandr Verdiev
03/11/2025, 11:01 PM2020-01-02T14:40:01.123456789Z
instead of
2020-01-02T14:40:01.123Z
, this would break the test, even though it is a valid value and the consumer would still be getting both options of the value in production.
From your suggestions, it seems that the recommendation is to create 4 tests instead of 1 - each testing a possible variant of the timestamp? 🙂
However, i do understand that timestamps are hard and if this is a limitation we need to work with, i guess it is not crucial and there are some regex workarounds.
Thank you for taking time to take a look into this!