Uploaded image for project: 'Commons BeanUtils'
  1. Commons BeanUtils
  2. BEANUTILS-239

[beanutils] Better implementation of SqlDateConverter.convert()

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.6
    • 1.8.0
    • None
    • None
    • Operating System: other
      Platform: Other

    • 30520

    Description

      The present implementation of SqlDateConverter.convert() has three cases to
      gerenarate new object from value parameter: If value was null, if value was a
      java.sql.Date instance and if value was another class instance. Above a piece
      of code:

      // If value was null
      if (value instanceof Date) {
      return (value);
      }
      // If value was not a java.sql.Date instance

      My propose is include 2 cases, between case of java.sql.Date instance and other
      class instance. This cases will what to do if value was a java.util.Date
      instance or a Calendar instance. In first case, it will be returned a new
      instance of java.sql.Date from value.getTime() value. In second case , it will
      be returned a new instance of java.sql.Date from value.getTimeInMillis() value.
      Like this:

      // If value was null
      if (value instanceof Date) {
      return (value);
      }
      if (value instanceof java.util.Date) {
      return new Date(((java.util.Date)value).getTime());
      }
      if (value instanceof Calendar) {
      return new Date(((Calendar)value).getTimeInMillis());
      }
      // If value was not a java.sql.Date instance

      IMHO, with this the convert method could be more accurated.
      Something similar could be done in SqlTimeConverter and SqlTimestampConverter.

      Attachments

        1. ASF.LICENSE.NOT.GRANTED--SqlTimestampConverter.java
          3 kB
          Rafael U. C. Afonso
        2. ASF.LICENSE.NOT.GRANTED--SqlTimeConverter.java
          3 kB
          Rafael U. C. Afonso
        3. ASF.LICENSE.NOT.GRANTED--SqlDateConverter.java
          3 kB
          Rafael U. C. Afonso

        Activity

          People

            Unassigned Unassigned
            r.u.c.afonso@uol.com.br Rafael U. C. Afonso
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: