2dor
2dor

Reputation: 1001

Spring Data Mongo No accessor to set final property that is initialized

I have a class that has included a final Set that is already initialized. Mongo converters doesn't see an accessor for the Set field and @Wither doesn't help, because it doesn't generate the method (due to the set being initialized). What can I do?

@Getter
@Setter
@Wither
@AllArgsConstructor
class A {
  private final Set<String> setOfStrings = new HashSet<>();
}

Exception received is

java.lang.UnsupportedOperationException: No accessor to set property final java.util.Set A.setOfStrings

I would like to keep the field initialized.

Upvotes: 2

Views: 2715

Answers (1)

2dor
2dor

Reputation: 1001

What I did was to remove default instantiation and instantiate in the constructor

Upvotes: 2

Related Questions