datanucleus-api-jdo icon indicating copy to clipboard operation
datanucleus-api-jdo copied to clipboard

Support for @Convert on types

Open tzaeschke opened this issue 2 years ago • 1 comments

Feature request

JDO and Datanucleus support @Convert annotations on fields and methods but not on types. It would be nice to add this feature, it is, for example, also present in JPA.

Specifically, the annotation @Convert would be changed to: @Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD})

If a persistent class (for example this) has a field of a type that is annotated with @Convert (for example this, then instances of the annotated class should always be converted, even if the fields or not annotated.

A test case, including a modified JDO-API jar, is available here. The relevant classes are:

  • https://github.com/tzaeschke/test-jdo/blob/master/src/main/java/tck/model/ConvertiblePoint.java
  • https://github.com/tzaeschke/test-jdo/blob/master/src/main/java/tck/pc/PCRectPointTypeAnnotated.java
  • https://github.com/tzaeschke/test-jdo/blob/master/src/test/java/org/datanucleus/test/TypeAnnotatedTest.java
  • https://github.com/tzaeschke/test-jdo/blob/master/src/test/java/org/datanucleus/test/AnnotationTestHelper.java

The other files are for reference to demonstrate that the the parallel implementation for @Convert on fields works as expected.

The issue is also discussed in JDO-709 starting October 17th, 2022.

tzaeschke avatar Jan 29 '23 13:01 tzaeschke

See https://github.com/datanucleus/datanucleus-core/issues/483. Not currently supported by DataNucleus for JDO or JPA (or Jakarta persistence), largely due to the fact that in all of the years of using converters not one person had requested it.

andyjefferson avatar Jan 29 '23 15:01 andyjefferson