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

[beanutils2] Support for nested properties and automatic conversion.

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • 2.0.0
    • None
    • None
    • Patch

    Description

      Please consider the attached patch for the commons-beanutils2 project. I added support for nested properties and automatic conversion. Excerpt from AutoConversionTest:

      final DateFormat dateFormat = new SimpleDateFormat("MMMM d, yyyy");
      final TransformerRegistry transformerRegistry = new TransformerRegistry()
          .register(new StringToDate(dateFormat))
          .register(new IntegerToString())
          .register(new StringToColor())
          .register(new IntegerToColor())
          .register(new StringToURL())
          .register(new StringToPhoneNumber());
      final PhoneNumber phoneNumber = new PhoneNumber();
      phoneNumber.setAreaCode("202");
      phoneNumber.setPrefix("456");
      phoneNumber.setLineNumber("1111");
      final Address address = new Address();
      address.setStreetAddress("1600 Pennsylvania Avenue Northwest");
      address.setCity("Washington");
      address.setStateCode("DC");
      address.setPostalCode("20500");
      address.setCountryCode("US");
      final Person person = new Person();
      person.setFirstName("Barack");
      person.setLastName("Obama");
      person.setBirthDate(dateFormat.parse("August 4, 1961"));
      person.setEyeColor(Color.decode("#362819"));
      person.setHairColor(GRAY);
      person.setPhoneNumber(phoneNumber);
      person.setAddress(address);
      person.setWebsite(new URL("https://www.barackobama.com/"));
      assertEquals(person, on(new Person(), transformerRegistry)
          .set("firstName").with("Barack")
          .set("lastName").with("Obama")
          .set("birthDate").with("August 4, 1961")
          .set("hairColor").with(0x808080)
          .set("eyeColor").with("#362819")
          .set("website").with("https://www.barackobama.com/")
          .set("phoneNumber").with("202-456-1111")
          .set("address").with(new Address())
          .set("address.streetAddress").with("1600 Pennsylvania Avenue Northwest")
          .set("address.city").with("Washington")
          .set("address.stateCode").with("DC")
          .set("address.postalCode").with(20500)
          .set("address.countryCode").with("US")
          .get());
      

      Thanks,
      Matt

      Attachments

        1. commons-beanutils2.conversion-only.patch
          35 kB
          Chris Mattmann
        2. commons-beanutils2.patch
          36 kB
          Chris Mattmann

        Issue Links

          Activity

            People

              Unassigned Unassigned
              mattmann Chris Mattmann
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated: