atos1990 / orika

Automatically exported from code.google.com/p/orika
0 stars 0 forks source link

Conversion between java.sql.Time and java.util.Date #76

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Converting between fields of type java.sql.Time and java.util.Date

What is the expected output? What do you see instead?

I suppose it should work by default but conversion fails with 
IllegalArgumentException on java.sql.Time.getDate(). This method is not 
supported.

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

Orika 1.4.0. Java 1.6.0_37

Please provide any additional information below.

Found a workaround with implementing and registering two unidirectional 
converters like this:

public class SqlTime2DateConverter extends CustomConverter<Time, Date> {
    @Override
    public Date convert(Time v, Type<? extends Date> t) {
        return v == null ? null : new Date(v.getTime());
    }
}

public class Date2SqlTimeConverter extends CustomConverter<Date, Time> {
    @Override
    public Time convert(Date v, Type<? extends Time> t) {
        return v == null ? null : new Time(v.getTime());
    }
}

Registered them with:
        factory.getConverterFactory().registerConverter(new SqlTime2DateConverter());
        factory.getConverterFactory().registerConverter(new Date2SqlTimeConverter());

An approach with a single bidirectional converter failed as I understand 
because sql.Time is assignable to util.Date.

Original issue reported on code.google.com by alex.che...@gmail.com on 9 Jan 2013 at 2:26

GoogleCodeExporter commented 9 years ago
Thanks for pointing this out. We were missing this mapping in our built-in 
data/time converters....we should be able to add this for the upcoming 1.4.1 
release

Original comment by matt.deb...@gmail.com on 10 Jan 2013 at 4:19

GoogleCodeExporter commented 9 years ago
Added support for java.sql.Date, java.sql.Time and java.sql.Timestamp to the 
builtin converters. 

Please give this a try with the latest from our snapshot repository (available 
in about 15 mins from this post)...

Original comment by matt.deb...@gmail.com on 11 Jan 2013 at 2:12

GoogleCodeExporter commented 9 years ago
Latest snapshot is available now; (there was a misconfiguration in build server)

Original comment by matt.deb...@gmail.com on 21 Jan 2013 at 6:20

GoogleCodeExporter commented 9 years ago
Fixed in 1.4.1

Original comment by elaat...@gmail.com on 10 Feb 2013 at 12:15