RuedigerMoeller / fast-serialization

FST: fast java serialization drop in-replacement
Apache License 2.0
1.59k stars 247 forks source link

Serialization of array of java.time.* fails if the array has length > 1 #177

Closed ghost closed 7 years ago

ghost commented 7 years ago

This program

import java.io.IOException;
import java.time.Duration;
import org.nustaq.serialization.FSTObjectOutput;
public class Foo {
    public static void main(String[] args) throws IOException {
        Object[] x = { Duration.ofDays(1), Duration.ofDays(2) };
        new FSTObjectOutput().writeObject(x);
    }
}

fails with

Exception in thread "main" java.lang.ClassCastException: java.time.Duration cannot be cast to java.io.Externalizable
    at org.nustaq.serialization.FSTObjectOutput.defaultWriteObject(FSTObjectOutput.java:523)
    at org.nustaq.serialization.FSTObjectOutput.writeObjectWithContext(FSTObjectOutput.java:446)
    at org.nustaq.serialization.FSTObjectOutput.writeArray(FSTObjectOutput.java:775)
    at org.nustaq.serialization.FSTObjectOutput.writeObjectWithContext(FSTObjectOutput.java:419)
    at org.nustaq.serialization.FSTObjectOutput.writeObjectInternal(FSTObjectOutput.java:319)
    at org.nustaq.serialization.FSTObjectOutput.writeObject(FSTObjectOutput.java:284)
    at org.nustaq.serialization.FSTObjectOutput.writeObject(FSTObjectOutput.java:193)
    at at.ac.ait.ariadne.gtfs.Foo.main(Foo.java:7)

(The exception occurs with several other types in java.time, not only Duration)

RuedigerMoeller commented 7 years ago

ah -the new 1.8 time api has not been tested yet .. thanks for the report

RuedigerMoeller commented 7 years ago

cannot reproduce. I tested using fst 2.48 your snippet as well this testcase:

    @Test
    public void test() throws IOException {
        FSTConfiguration conf = FSTConfiguration.createDefaultConfiguration();
        Object[] x = { Duration.ofDays(1), Duration.ofDays(2) };
        Object[] res = (Object[]) conf.asObject(conf.asByteArray(x));
        Assert.assertTrue( x[0].equals(res[0]) && x[1].equals(res[1]));
    }

tried JDK1.8_u45 and JDK1.8_u121