Giter Site home page Giter Site logo

Comments (9)

otaviojava avatar otaviojava commented on May 23, 2024 1

@m4ttek thank you for those points; we will work to release in this next version.

from jnosql.

m4ttek avatar m4ttek commented on May 23, 2024 1

@otaviojava great idea!

And if it's not a problem, I'd also suggest supporting some kind of annotation for entity types like @EntitySerializer and @EntityDeserializer with required argument of a provided class type that must implement generic Serializer or Deserializer interface with proper implementation for Arango. Thus, it would be easier to exchange chosen database in any future.

from jnosql.

otaviojava avatar otaviojava commented on May 23, 2024 1

I have the draft work here:

eclipse/jnosql-databases#242

from jnosql.

m4ttek avatar m4ttek commented on May 23, 2024

To give more context - I'd like to provide user-data serde, according to https://www.arangodb.com/docs/stable/drivers/java-reference-serialization.html#custom-serializers

from jnosql.

otaviojava avatar otaviojava commented on May 23, 2024

I got an idea using the properties:

jnosql.arangodb.deserializer.1=the class path
jnosql.arangodb.deserializer.2=the class path
jnosql.arangodb.seserializer.1=the class path
jnosql.arangodb.seserializer.2=the class path

I will create the implementation and ask for your help to review it.

from jnosql.

otaviojava avatar otaviojava commented on May 23, 2024

Hey @m4ttek,

Do you know about the @org.eclipse.jnosql.mapping.Convert annotation? This annotation allows developers to define field-level converters, providing a way to map custom data types between the database and Java objects.

Here's a brief explanation of how it works:

What is @org.eclipse.jnosql.mapping.Convert?

The @org.eclipse.jnosql.mapping.Convert annotation specifies that a field in a Java class should be converted using a custom converter before being stored in the database or retrieved from it. It is particularly useful when you map non-standard or complex data types to and from the database.

How to Use @org.eclipse.jnosql.mapping.Convert

To use the @org.eclipse.jnosql.mapping.Convert annotation, you need to follow these steps:

  1. Annotate Your Field: Place the @Convert annotation above the field you want to convert. In your example, it's used to convert a Currency field.

    @Column
    @Convert(MoneyConverter.class)
    private Currency currency;

    Here, the currency field will be converted using the MoneyConverter class.

  2. Implement the Converter: You'll also need to create a custom converter class that implements the AttributeConverter interface. This interface defines two methods: convertToDatabaseColumn and convertToEntityAttribute.

    public class MoneyConverter implements AttributeConverter<Currency, String> {
    
        @Override
        public String convertToDatabaseColumn(Currency attribute) {
            return attribute.getCurrencyCode();
        }
    
        @Override
        public Currency convertToEntityAttribute(String dbData) {
            return Currency.getAvailableCurrencies().stream()
                    .filter(c -> dbData.equals(c.getCurrencyCode()))
                    .findAny().orElse(null);
        }
    }

    In your MoneyConverter class, you've provided implementations for these methods. The convertToDatabaseColumn method is responsible for converting the Java object to a format that can be stored in the database, and convertToEntityAttribute does the reverse – it converts data retrieved from the database into a Java object.

Using this approach gives you fine-grained control over how data is stored and retrieved from the database, allowing you to handle custom data types flexibly.

Ref: https://github.com/eclipse/jnosql/blob/main/MAPPING.adoc

from jnosql.

m4ttek avatar m4ttek commented on May 23, 2024

Ok, I get it, but still it doesn't allow me to specify how serde should work for whole entity (like standard Java Externalizable interface).

So, maybe, we should look into it from the other side and give access to creating custom ArangoDB instance with custom serialization objects if needed?

from jnosql.

otaviojava avatar otaviojava commented on May 23, 2024

Ok, I get it, but still it doesn't allow me to specify how serde should work for whole entity (like standard Java Externalizable interface).

So, maybe, we should look into it from the other side and give access to creating custom ArangoDB instance with custom serialization objects if needed?

Yes, it makes sense to use the driver directly in that case.

from jnosql.

otaviojava avatar otaviojava commented on May 23, 2024

As we discussed, this one will close as non-fixed.

We have this method that might be helpful:

https://github.com/eclipse/jnosql-databases/blob/main/jnosql-arangodb/src/main/java/org/eclipse/jnosql/databases/arangodb/mapping/ArangoDBTemplate.java#L63

from jnosql.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.