jsonschema2pojo icon indicating copy to clipboard operation
jsonschema2pojo copied to clipboard

Cast parent builder to this builder return type

Open nielspardon opened this issue 3 years ago • 2 comments
trafficstars

This PR adds wrapper methods to the builder class calling the withXXX builder method of the parent builder and casting the result to the class of the current builder, e.g.:

public static abstract class ChildBuilderBase<T extends Child> extends Parent.ParentBuilderBase<T> {
  ...
  @Override
  public Child.ChildBuilderBase<T> withTimestamp(Instant timestamp) {
    return ((Child.ChildBuilderBase<T> ) super.withTimestamp(timestamp));
  }
  ...
}

This allows to actually use inherited builders with a fluent API.

Fixes https://github.com/joelittlejohn/jsonschema2pojo/issues/1242

nielspardon avatar Jul 15 '22 07:07 nielspardon

Looks like there is some problem with the way this interacts with the 'inner builder' option.

joelittlejohn avatar Aug 06 '22 11:08 joelittlejohn

Looks like there is some problem with the way this interacts with the 'inner builder' option.

Sorry for that. I think I found a better solution that avoids this issue.

nielspardon avatar Aug 08 '22 13:08 nielspardon