Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [nosql-dev] @Convert annotation for the Entities (Document)

Hey Dmitry, how are you?

Please, open a PR, thus we can talk about it.

What do you think?

Thank you for your contibuition.


On Tue, May 3, 2022 at 9:35 AM Dmitry Repchevsky via nosql-dev <nosql-dev@xxxxxxxxxxx> wrote:
Hello,

Implementing the polymorphism via AttributeConverter interface, I found
that it supposed for the primitive types.
I still can make it works, but IMHO the behavior should be changed. Here
is the problem:

https://github.com/eclipse/jnosql/blob/d68add32d7a09e601c4ef3aef666c14cd885c13e/mapping/mapping-document/src/main/java/org/eclipse/jnosql/mapping/document/DocumentFieldConverters.java#L130

if (Objects.nonNull(document)) {
     Value value = document.getValue();
     Optional<Class<? extends AttributeConverter<X, Y>>>
optionalConverter = field.getConverter();
     if (optionalConverter.isPresent()) {
         AttributeConverter<X, Y> attributeConverter =
converter.getConverters().get(optionalConverter.get());
         Object attributeConverted =
attributeConverter.convertToEntityAttribute((Y) value.get());
         field.write(instance,
field.getValue(Value.of(attributeConverted)));
     } else {
         field.write(instance, field.getValue(value));
     }
}

The code supposes that for the @Converter the document that describes
the value is a primitive (value.get())

This obliges to define the converter as:

@Convert(MeasurementValueCoverter.class)
private MeasurementValueEntity measurementValue;
...
public class MeasurementValueCoverter implements
AttributeConverter<MeasurementValueEntity, List<Document>> {

Note, that List<Document> in this case is not the document itself, but
its properties!
IMHO, for the Entities converter should receive the Document, so we can
parse it correctly.

Cheers,

Dmitry

_______________________________________________
nosql-dev mailing list
nosql-dev@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/nosql-dev


--
Otávio Santana

Back to the top