kshchepanovskyi / protostuff-googlecode-exported

Automatically exported from code.google.com/p/protostuff

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

GoogleCodeExporter opened this issue · comments

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

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

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