Stylianos Gakis
05/24/2022, 4:16 PMJavaLocalDateAdapter.toJsonString(LocalDate.of(2021, 4, 11))
I get back the string ""2021-04-11""
.
Now if I do a test case like this:
val localDate = LocalDate.of(2021, 4, 11)
val jsonRepresentation = JavaLocalDateAdapter.toJsonString(localDate)
val buffer = Buffer().write(jsonRepresentation.encodeUtf8())
val jsonReader = BufferedSourceJsonReader(buffer)
val parsedAgain = JavaLocalDateAdapter.fromJson(jsonReader, CustomScalarAdapters.Empty)
assertThat(parsedAgain).isEqualTo(localDate)
It passes fine as expected.
However when I am actually using it on the builder, it crashes at the adapter, since it tries to then parse ""2021-04-11""
directly, and LocalDate fails to do so. In this line in particular, the nextString!!
returns the value with those double quotes and it fails.
In the code snippet I put above, the encodeUtf8() part seems to turn it into a string with a single quote which makes this work, and maybe this isn’t happening in the test builders code? I am not quite sure what piece of the puzzle is going wrong, so I am posting this here in case you may have a better idea.
Edit: For people who might read this at some future time and might be confused. I had simply misread that it was giving me back a String with double quoted strings, but it was just that in the debugger view in IntelliJ, to indicate a string it wraps it with quotations in the UI. The String I got back was in fact "2021-04-11"
as expected and the workaround for the test builders was to strip the ‘“’ from the start and the end of the resulting string. This resulted in the String 2021-04-11
which was correctly parsed from the LocalDate.parsembonnin
05/24/2022, 4:25 PMtoJsonString
puts extra quotes.. Which might be what we want actually"
but that's far from idealStylianos Gakis
05/24/2022, 5:54 PM