cloudbees-oss / zendesk-java-client

A Java client library for interacting with Zendesk
https://developer.zendesk.com/rest_api/docs/api-clients/java#zendesk-java-client-by-cloudbees
Apache License 2.0
153 stars 252 forks source link

Add builder API to entities #699

Closed internetstaff closed 2 months ago

internetstaff commented 5 months ago

Any chance of adding e.g. lombok @Builders for entities?

PierreBtz commented 5 months ago

Sorry, I'd rather not add lombok to this project. Feel free to provide a PR with builders though.

internetstaff commented 5 months ago

I can understand your lombok hesitancy, having gone through that myself many years ago.

I'm concerned, however, that otherwise builders will add a large amount of clutter to the model classes.

Do you have an idea of what you'd want that to look like?

PierreBtz commented 4 months ago

I'm concerned, however, that otherwise builders will add a large amount of clutter to the model classes.

I agree. I've had my eyes for some months on https://github.com/jonas-grgt/bob that look like a promising alternative to lombok. It's still a bit young but promising. I'll try experimenting a bit with it see if we could maybe introduce it in this project.

PierreBtz commented 4 months ago

Mhh, this dependency wouldn't fit the bill right now, it doesn't handle inheritance well (not surprised, it's also often an issue with Lombok anyway...).

Rewinding a bit here, what's the motivation for using builders? Is it to have a less verbose/more compact code when you instanciate entities? In which case, would fluent setter be enough, ie instead of writing something like:

  private Ticket createSampleTicket() {
    Ticket ticket = new Ticket();
    ticket.setId(Math.abs(RANDOM.nextLong()));
    ticket.setComment(new Comment(TICKET_COMMENT1));
    ticket.setUpdatedAt(NOW);
    ticket.setCustomStatusId(Math.abs(RANDOM.nextLong()));
    return ticket;
  }

you'd write:

   private Ticket createSampleTicket() {
    return new Ticket()
            .setId(Math.abs(RANDOM.nextLong()))
            .setComment(new Comment(TICKET_COMMENT1))
            .setUpdatedAt(NOW)
            .setCustomStatusId(Math.abs(RANDOM.nextLong()));
  }
internetstaff commented 4 months ago

Fluent setters would be an improvement, but tbh I seem to rarely see that as a pattern anymore relative to builders. :shrug:

github-actions[bot] commented 2 months ago

This issue/PR is stale because it has been opened 60 days with no activity. Remove stale label or comment or this will be closed in 7 days