graphql-java-codegen
graphql-java-codegen copied to clipboard
Generate models with immutable list / map getters
Is your feature request related to a problem? Please describe.
My project is in the stage of code quality checks and associated stuff, and I'm currently using a code scanner that is flagging out the issue that generated model files have getters for list and object types that are not immutable. For example, I'm getting the spotbugs EI_EXPOSE_REP error with lists.
Describe the solution you'd like
Is it possible for the generated classes to have list and map attributes be returned in an immutable manner? In my understanding, for lists that would be List.copyOf(listAttribute).
The only problem is that Java does not natively support immutable collections(such as singletonList or Collections.unmodifiableXXX not a good choice). This requires an external library.
The only problem is that Java does not natively support immutable collections(such as
singletonListorCollections.unmodifiableXXXnot a good choice). This requires an external library.
@jxnu-liguobin would it be possible to do something like List.copyOf()?
But how do I make a list immutable? Immutable collection that avoid modification by throwing exceptions are not a good design. Because this will cause a runtime exception. This is also the default implementation of the Java collection library.