#161 Timestamp mapping broken

Dozer v5.0


Mapping with java.sql.Timestamp is broken because nanoseconds aren't mapped.

The problem is that java.sql.Timestamp is a java.util.Date but as stated on the API docs it shouldn't considered properly as a subclass.

I've seen other libraries distinguish subclasses inside a java.util.Date instance of.

this is a JUnit3 test to show the problem.

thanks again for your job

paolo antinori & daniele sabaini


  • sonicaaaa

    sonicaaaa - 2009-01-29

    File Added: TestTimestamp.java

  • sonicaaaa

    sonicaaaa - 2009-01-29

    JUnit 3 Test

  • ed

    ed - 2009-01-31


    Well spotted. The bug is in the DateConverter that threats it as a simple Date object with miliseconds and simple ignored the timestamp.

    Btw: thanks for the test case, but it doesn't work as your methods are package protected so Dozer won't map them unless you map on field level.

    I have added a modified version of your test that works.

    -- Ed

  • ed

    ed - 2009-01-31

    Appearantly I don't seem to be able to attach a file as I am not the creator of this bug :(..

    Anyway, the bug test is attached below.

    BTW: another thing, you might want to copy-by-reference these kind of primitive objects (String, Date, Timestampt, etc...). In my case I don't need to convert these kind of objects, but that's just me... (you configure this the mapping xml, see doc's)

    -- Ed

    public class TestTimestamp extends TestCase {

    public void testNanos() {
    DozerBeanMapper mapper = new DozerBeanMapper();

    T t = new T() {
    timestamp = new java.sql.Timestamp(1L);

    T t2 = mapper.map(t, T.class);

    assertEquals(t.timestamp, t2.timestamp);

    public static class T {
    java.sql.Timestamp timestamp;

    public java.sql.Timestamp getTimestamp() {
    return timestamp;

    public void setTimestamp(java.sql.Timestamp timestamp) {
    this.timestamp = timestamp;



  • sonicaaaa

    sonicaaaa - 2009-01-31

    hi. at first we added the test without T class that was in a different file, then i included without actually recheck it, sorry.

    thanks for tip about copy by ref. we're not sure we can use it without side effects but we'll try!

  • dmitry (lv)

    dmitry (lv) - 2009-02-05

    Fixed, Calendar is now supported as resulting object as well as Timestamp.
    Will be included in 5.0 release.

  • dmitry (lv)

    dmitry (lv) - 2009-02-05
    • milestone: 897300 --> Dozer v5.0
    • assigned_to: nobody --> buzdin
    • status: open --> closed-fixed

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks