5

I am generating the Java from XML. The setters all return void. If they returned "this", then they could be called in a chain. Is there a way ( an easy way ) to make it generate setters that "return this;" ?

Nick Perkins
  • 8,034
  • 7
  • 40
  • 40

2 Answers2

4

Take a look at the JAXB Fluent API Plugin.

 USAddress address = new USAddress()
            .withName(name)
            .withStreet(street)
            .withCity(city)
            .withState(state)
            .withZip(new BigDecimal(zip));
lexicore
  • 42,748
  • 17
  • 132
  • 221
3

What you are talking about is the builder pattern. If you are interested in generating classes from XML that have the additional setter methods returning this for chaining, take a look at the following post: Is there a JAXB Plugin which generates Builders?

Community
  • 1
  • 1
drembert
  • 1,246
  • 1
  • 9
  • 18