5

I have some code using Immutables (https://immutables.github.io/) which generates a ImmutableEntity class with a method like:

public static ImmutableEntity of(EntityId id,
                                  Locale language,
                                  String text)) {
  return validate(new EntityMeldung(id, language, text));
}

but to work with MongoDB POJOs I need that method to have annotations like:

@BsonCreator
public static ImmutableEntity of(@BsonProperty("id") EntityId id,
                                  @BsonProperty("language") Locale language,
                                  @BsonProperty("text") String text)) {
  return validate(new ImmutableEntity(id, language, text));
}

The Entity interface only defines some getters and I'd rather continue to let Immutables generate the ImmutableEntity class and methods like of()

Should I be looking at Annotation Injection?

Nic Cottrell
  • 9,401
  • 7
  • 53
  • 76
  • 2
    Possible duplicate of [Carry forward annotation from interface to generated java class when using Immutables](https://stackoverflow.com/questions/42631472/carry-forward-annotation-from-interface-to-generated-java-class-when-using-immut) – Rcordoval Jun 05 '18 at 08:06
  • @Rcordoval similar question but not a duplicate since this `of` method doesn't exist in `Entity` - it's generated by Immutables – Nic Cottrell Jun 05 '18 at 11:12

0 Answers0