xiijima / protostuff

Automatically exported from code.google.com/p/protostuff
Apache License 2.0
0 stars 0 forks source link

add protobuf support for java.sql.{Date|Timestamp|Time} types #134

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. create a class with java.sql.Timestamp field
2. use ProtostuffIOUtil.toByteArray() to serialize the object
3. an exception will be thrown

What is the expected output? What do you see instead?
the object should be serialized correctly. Exception 

What version of the product are you using? On what operating system?
1.0.7

Please provide any additional information below.

Original issue reported on code.google.com by aser...@gmail.com on 3 Sep 2012 at 6:34

GoogleCodeExporter commented 8 years ago
See http://code.google.com/p/protostuff/wiki/Delegate

Its easy to add, for example java.sql.Date:
        public void writeTo(Output output, int number, java.sql.Date value, 
                boolean repeated) throws IOException
        {
            output.writeFixed64(number, value.getTime(), repeated);
        }

        public java.sql.Date readFrom(Input input) throws IOException
        {
            return new java.sql.Date(input.readFixed64());
        }

If you want the string representation:

        public void writeTo(Output output, int number, java.sql.Date value, 
                boolean repeated) throws IOException
        {
            output.writeString(number, value.toString(), repeated);
        }

        public java.sql.Date readFrom(Input input) throws IOException
        {
            return java.sql.Date.valueOf(input.readString());
        }

Original comment by david.yu...@gmail.com on 3 Sep 2012 at 8:43

GoogleCodeExporter commented 8 years ago
Thanks, David. Do you think it is a good idea to natively (out of the box)  
support these classes ?

Original comment by aser...@gmail.com on 4 Sep 2012 at 3:01