Open lostiniceland opened 3 years ago
Hi @lostiniceland ,
would PropertyVisibilityStrategy
be viable to you? You can force Yasson to use non public fields/accessors.
I did try this one but it failed because Records where not supported at the time. Since this PR is now merged, I can give it another try...once the new version is available in Quarkus. Or I test without a Record.
Since, for other reasons, we still cannot use records I was trying to achieve something similar with some package-private DTOs and using the PropertyVisibilityStrategy
.
The serialization worked fine, but Yasson cannot deserialize with the following message: class org.eclipse.yasson.internal.ReflectionUtils cannot access a member of class some.MyDTO with modifiers "" at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Reflection.java:392)
class MyDTO {
enum SomeEnum {
A,
B
}
public SomeEnum fieldA,
public String fieldB
}
Note, that I had to make the fields public due to an issue in MapStruct which is hopefully resolved soon.
The issue seems to be caused by the default-constructor. When I add a public default-constructor the error occurs as well but with a slightly differen message with modifiers "public"
(public in quotes).
Is your feature request related to a problem? Please describe. Assuming all classes responsible communication with some external resource or a JAX-RS endpoint, there is no need to make the DTOs public. Once they are public, misuse can easily happen.
Describe the solution you'd like The reflection api has the capabilities to make fields accessible which are not public. JSONB/Yasson should make use of this and dont force public accessors onto its users.
Describe alternatives you've considered Jackson does support package-private visibility, but some apis are hardwired to json-b.
Additional context The Java bean-convention, despite its success, has polluted the java ecosystem with its overuse of public. Most developers just dont think about accessibility anymore. They just create a class and make everything public because that was the way it was necessary for instance to work with Hibernate. The Java community should leave those days behind.