1

I just stumbled upon the GWT com.google.web.bindery.autobean.shared.AutoBean and learned that I have to write and maintain AutoBean Interfaces for my classes if I want to create AutoBeans from them.

This looks like a lot of boilerplate code for me. Is there a way to create those AutoBeans by code generation or something?

To clarify what I want to do:

I have existing classes like:

public class Person {

  private String name;

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

}

In the end I want to use AutoBeanUtils.getAllProperties() so the AutoBean needs to have all properties of the original class.

But to use AutoBeans I have to define interfaces like

public interface PersonAutoBeanDefinition {  
  String getName();  
}

Of course this works but I wondered if I could generate these interfaces via Annotations or something because maintaining bigger objects where different developers work on sounds like a pain.

Sebastian
  • 5,721
  • 3
  • 43
  • 69
  • You can probably roll your own, using Java APT. But otherwise I don't think there is any off-the-shelf product. – Andrei Jul 18 '17 at 07:19
  • And the alternative is usually something like creating entire beans - fields, getters/setters. With AutoBeans, all you need is the method _signature_ of the getter and setter. What are you hoping to generate from? – Colin Alworth Jul 18 '17 at 12:23
  • BTW, unless you have a strong need for some AutoBean-specific features, I wouldn't use it. JsInterop on client side, Jackson or GSON on server side work just as well, if not better. – Thomas Broyer Jul 18 '17 at 18:00
  • Edited my question, hope intention is clearer now. – Sebastian Jul 19 '17 at 11:21
  • I have used xtend for things like this, with great success – Tony BenBrahim Jul 28 '17 at 15:51

0 Answers0