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

[beanutils] Preserving DynaBean Property Ordering

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • None
    • 2.0.0
    • DynaBean
    • None
    • Operating System: All
      Platform: All

    • 37825

    Description

      The order of properties is not preserved when using the beanutils to fetch
      properties from a DynaBean. Since DynaBeans use an array to define properties
      it is natural desire to use the order of this array to do things with a
      DynaBean. With a 2 line patch to BeanUtilsBean.java, it can be made to return
      a LinkedHashMap for DynaBean properties which preserves the ordering of these
      properties.

      This patch is particularly usefull if you are using the <display> tag to
      display DynaBeans. Several people have suggested a patch like this on the
      <display> tag mailing list.

          • BeanUtilsBean.java
          • BeanUtilsBean.java.ordered
          • 26,31 ****
          • 26,32 ----
            import java.util.ArrayList;
            import java.util.Collection;
            import java.util.HashMap;
            + import java.util.LinkedHashMap;
            import java.util.Iterator;
            import java.util.Map;
            import java.util.WeakHashMap;
          • 487,493 ****
            log.debug("Describing bean: " + bean.getClass().getName());
            }

      ! Map description = new HashMap();
      if (bean instanceof DynaBean)

      { DynaProperty descriptors[] = ((DynaBean) bean).getDynaClass().getDynaProperties(); --- 488,494 ---- log.debug("Describing bean: " + bean.getClass().getName()); }

      ! Map description = new LinkedHashMap();
      if (bean instanceof DynaBean) {
      DynaProperty descriptors[] =
      ((DynaBean) bean).getDynaClass().getDynaProperties();

      Attachments

        Activity

          People

            Unassigned Unassigned
            fick@fgm.com Martin Fick
            Votes:
            1 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated: