Giter Site home page Giter Site logo

Comments (3)

anidotnet avatar anidotnet commented on June 5, 2024

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.

magicDGS avatar magicDGS commented on June 5, 2024

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.

anidotnet avatar anidotnet commented on June 5, 2024

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)

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.