Comments (9)
@m4ttek thank you for those points; we will work to release in this next version.
from jnosql.
@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.
I have the draft work here:
from jnosql.
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.
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.
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:
-
Annotate Your Field: Place the
@Convert
annotation above the field you want to convert. In your example, it's used to convert aCurrency
field.@Column @Convert(MoneyConverter.class) private Currency currency;
Here, the
currency
field will be converted using theMoneyConverter
class. -
Implement the Converter: You'll also need to create a custom converter class that implements the
AttributeConverter
interface. This interface defines two methods:convertToDatabaseColumn
andconvertToEntityAttribute
.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. TheconvertToDatabaseColumn
method is responsible for converting the Java object to a format that can be stored in the database, andconvertToEntityAttribute
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.
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.
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.
As we discussed, this one will close as non-fixed.
We have this method that might be helpful:
from jnosql.
Related Issues (20)
- Increase the test covery at the Repository specializations [BUG]
- [BUG] dynamodb fixed to primary key type of string HOT 2
- [BUG] Lack of descriptive error when trying to inject a Repository with type without @Entity annotation HOT 4
- [Feat.] Make the Couchbase DocumentManager implementation supports the count method HOT 1
- Add CI support for Java 21 HOT 1
- [BUG] query specification doesnt allow for dashes in tablenames HOT 2
- Add CI into the JNoSQL Database project to support for Java 21 HOT 2
- Add CI into the JNoSQL Extensions project to support for Java 21 HOT 2
- [BUG] deleteAll does not delete anything in Arango Repository HOT 1
- [BUG] ArangoRepository save method interally uses updateDocument instead of replaceDocument HOT 2
- [BUG] It is not possible to use jnosql with JPMS HOT 8
- [BUG] Embeddable list of nested object cannot be saved HOT 16
- Support for @Index annotation HOT 1
- Standardize Criteria Query and Introduce KeySet Pagination
- [BUG] Do not throw MappingException for other Jakarta Data providers
- Support for Java Records and Builder Pattern in Eclipse JNoSQL Lite
- Integrating Support for Default Methods in Repository Interfaces with CDI Lite
- Enhancement of JNoSQL with Dual Support for Apache Tinkerpop and Open Cypher Standards
- [BUG] Problem with Inheritance with enum field HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jnosql.