dubbo icon indicating copy to clipboard operation
dubbo copied to clipboard

Protostuff deserializes LocalTime, the value is incorrect

Open feixz opened this issue 7 years ago • 3 comments

  • [x] I have searched the issues of this repository and believe that this is not a duplicate.
  • [x] I have checked the FAQ of this repository and believe that this is not a duplicate.

Environment

  • Dubbo version: v2.7.3
  • Operating System version: OSX
  • Java version: javac 1.8.0_202
  • Kotlin version: 1.3.40

Steps to reproduce this issue

data class Data(var list: MutableList<CustomizeDateTime> = mutableListOf()) : Serializable {}

// Get the correct result when time has no default value or is null
// CustomizeDateTime(var time: LocalTime) or CustomizeDateTime(var time: LocalTime? = null)
data class CustomizeDateTime(var time: LocalTime = LocalTime.parse("12:00:00")) : Serializable {}

private var byteArrayOutputStream: ByteArrayOutputStream? = null
private var protostuffObjectOutput: ProtostuffObjectOutput? = null
private var protostuffObjectInput: ProtostuffObjectInput? = null
private var byteArrayInputStream: ByteArrayInputStream? = null

@Throws(IOException::class)
private fun flushToInput() {
    this.protostuffObjectOutput?.flushBuffer()
    this.byteArrayInputStream = ByteArrayInputStream(byteArrayOutputStream?.toByteArray())
    this.protostuffObjectInput = ProtostuffObjectInput(byteArrayInputStream)
}

@Before
@Throws(Exception::class)
fun setUp() {
    this.byteArrayOutputStream = ByteArrayOutputStream()
    this.protostuffObjectOutput = ProtostuffObjectOutput(byteArrayOutputStream)
}

@Test
fun `Test List LocalTime`() {
    val times = mutableListOf(
            CustomizeDateTime(LocalTime.parse("08:00:00")),
            CustomizeDateTime(LocalTime.parse("12:00:00")),
            CustomizeDateTime(LocalTime.parse("19:01:10")))
    val data = Data(times)
    this.protostuffObjectOutput?.writeObject(data)
    this.flushToInput()

    val serializedTime = protostuffObjectInput?.readObject()
    println(serializedTime)
}

Expected Result

Data(list=[CustomizeDateTime(time=08:00), CustomizeDateTime(time=12:00), CustomizeDateTime(time=19:01:10)])

Actual Result

Data(list=[CustomizeDateTime(time=19:01:10), CustomizeDateTime(time=19:01:10), CustomizeDateTime(time=19:01:10)])

If there is an exception, please attach the exception trace:

Just put your stack trace here!

feixz avatar Jul 21 '19 14:07 feixz

looks like protostuff doesn't support Java8 well, let's investigate it in 2.7.5

beiwei30 avatar Jul 31 '19 12:07 beiwei30

ProtostuffObjectOutputTest#testCustomizeTimeList

    @Test
    public void testCustomizeTimeList() throws IOException, ClassNotFoundException {

        List<LocalTime> list = new ArrayList<LocalTime>();

        LocalTime localTime = LocalTime.parse("12:00:00");
        LocalTime localSecondTime = LocalTime.parse("13:00:00");
        LocalTime localThirdTime = LocalTime.parse("14:00:00");
        list.add(localTime);
        list.add(localSecondTime);
        list.add(localThirdTime);

        LocalTimeList timeList = new LocalTimeList(list);
        this.protostuffObjectOutput.writeObject(timeList);
        this.flushToInput();

        LocalTimeList serializedTime = protostuffObjectInput.readObject(LocalTimeList.class);
        assertThat(serializedTime, is(timeList));
    }

the test method can work successfully, there's no problem in LocalTime serialization

icankeep avatar May 16 '21 14:05 icankeep

&READY-TO-CLOSE&

icankeep avatar May 16 '21 14:05 icankeep