Comments (3)
JacksonMapperModule
is working as expected here. The culprit here is the annotation - @JsonInclude(JsonInclude.Include.NON_EMPTY)
. You are instructing the internal ObjectMapper
to ignore all null fields. This is resulting an empty document while validating the entity. Remove the annotation and you will be good.
On another note, if you don't have access to the model definition, you can take a look into the EntityConverter
here. And also try to avoid use the same model definition for your presentation layer and persistence layer if you are doing it already.
from nitrite-java.
I know that I am instructing the model to serialize as an empty object, but I am not sure why the nitriteDB cannot store an empty document. I cannot even retrieve an ObjectRepository
, which is a bit weird because it is trying to use an empty document anyway to check if it is possible to create it.
Regarding the architectural recommendation, I agree that separating concerns and using to some extend clean/layered architecture is a good practice, but not on all use-cases. I am plannig to use this library for different products, but specifically for the one this issue is intented the benefit of separating it is not given (as it is a data-product where the actual data, model and database is the final deliverable), so having a model that is delivered with constraints imposed by the DB is something that is somehow against the specific use-case.
In any case, I will check further the possibilities of the DB (which I am really interested in using, to be honest, but I am still in evaluation phase) and check if having an EntityConverter
is worth from maintenance purposes, ass I would prefer to have the jackson-mapper as an out-of-the-box solution.
Last but not least, thanks for your input and help. I was not aware that there are many assumptions on the library for this intended behavior. My 2 cents is that it would be worth to document that with the JacksonMapperModule
it is expected that the serialization of an empty object is not an empty json-document, as otherwise is surprising why there is a failure on the object-repository getter method.
from nitrite-java.
The purpose of the entity validation before opening an object repository is to check if the entity type
- Is not a value type
- Is not a wrapper object
- Not an array type
- Has at-least one user defined field
This conditions are applicable for all types of NitriteMapper
implementations.
In case of @JsonInclude(JsonInclude.Include.NON_EMPTY)
in your example, the JacksonMapper
is creating an empty document like - {}
which fails the condition - Has at-least one user defined field. This condition is to ensure that an object repository does not contain a bunch of empty documents (if you really need such, use NitriteCollection
instead).
Instead of {}
what Nitrite expecting is kind of a skeleton document where all fields are there but no values:
{
"id": null,
"name": null
}
I hope, this clear your confusion.
from nitrite-java.
Related Issues (20)
- nitriteMapper is null? HOT 1
- Add 4.x.x+ to maven repository
- NitriteMapper does not give enough info about the type HOT 4
- IndexingException: indexing on arrays or collections for field formula are not supported HOT 1
- Longs become Integers after export/import HOT 7
- Migrating from 3.x to 4.x: Database file is corrupted HOT 7
- possible memory leak HOT 1
- org.h2.mvstore.Chunk.accountForRemovedPage NPE HOT 2
- MVStore claims to have unsaved changes after calling nitriteDatabase.getCollection(...) HOT 5
- NitriteCollection.update slow when unrelated properties in document are indexed HOT 6
- EntityConverter toDocument HOT 3
- KotlinXSerializationMapper decodes lists to be size 1 always HOT 1
- Possibiltity to index a field with both text and non-unique/unique filter HOT 3
- Incorrect result when searching indexed column HOT 1
- Support JPMS HOT 6
- Feature request: method for retrieving all document ids in a collection faster HOT 1
- Search for _id always returns an iterator with an element HOT 2
- org.dizitart.no2.common.tuples.Pair cannot be cast to class java.lang.Comparable HOT 4
- @Indices is not neccessary to use, multiple @Index annotations on class are allowed HOT 1
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 nitrite-java.