Skip to main content

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

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



Back to the top