Skip to content

Instantly share code, notes, and snippets.

@haohcraft
Last active March 2, 2020 04:46
Show Gist options
  • Save haohcraft/ec4ea68404144cefedb04c64e4e946cc to your computer and use it in GitHub Desktop.
Save haohcraft/ec4ea68404144cefedb04c64e4e946cc to your computer and use it in GitHub Desktop.
@DisplayName("Given a value with two data format, When use setDateFormat on GsonBuilder and a simpleDateFormat, Then return as expected")
@Test
fun testSetDateFormatWithSimpleDateFormat() {
val gson = GsonBuilder().apply {
setDateFormat("yyyy-MM-dd HH:mm:ss")
}.create()
val dateFormatter = SimpleDateFormat(targetFormat, Locale.US)
val result = gson.fromJson(testJsonString, SerializationTestData::class.java)
assertEquals("2020-03-23", dateFormatter.format(result.startDate))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment