marklogic / java-client-api

Java client for the MarkLogic enterprise NoSQL database
https://docs.marklogic.com/guide/java
Apache License 2.0
58 stars 72 forks source link

Removing the canonical class name from the document when using PojoRepository #558

Closed sanjuthomas closed 4 years ago

sanjuthomas commented 7 years ago

This is a question -

I was testing the PojoRepository.write and noticed that the documents are created with the canonical name of the class. Is there a way I can use the simple name of the class?

Say for example, instead of having this

{
  "org.sanju.ml.client.odm.pojo.QuoteRequest": {
    "id": "Q-12-01-2015-123-123",
    "symbol": "AAPL",
    "quantity": 120,
    "client": {
      "org.sanju.ml.client.odm.pojo.Client": {
        "id": "C110",
        "account": {
          "org.sanju.ml.client.odm.pojo.Account": {
            "id": "A-100-1100"
          }
        }
      }
    }
  }
}

Can I have this?

{
  "id": "Q-12-01-2015-123-123",
  "symbol": "AAPL",
  "quantity": 120,
  "client": {
    "id": "C110",
    "account": {
      "Account": {
        "id": "A-100-1100"
      }
    }
  }
}

Also, how do I control the URI of the document when I use PojoRepository?

sammefford commented 7 years ago

Is there a way I can use the simple name of the class?

You definitely can. I would recommend you use JacksonDatabindHandle for that. That way you'll have full control over the serialization. PojoRepository, on the other hand, is more useful when you don't care about the structure of the persisted content, and are looking at things from a pure POJO perspective.

Please let us know if you find that using JacksonDatabindHandle together with JSONDocumentManager is significantly more difficult than using PojoRepository. For some related explanation, see this blog post about io shortcuts, the javadoc section "Registering New IO Representations for Shortcut Methods", and JacksonDatabindTest.beforeTest and JacksonDatabindTest.JsonCityWriter .

Also, how do I control the URI of the document when I use PojoRepository?

Again, that's more in your control when you use JSONDocumentManager. With PojoRepository you only control which property to annotate with @Id and the values in those properties. If you need more control over the uri, please try JSONDocumentManager.

sanjuthomas commented 7 years ago

Thanks @sammefford , I will check and confirm.

sammefford commented 7 years ago

@sanjuthomas, I'm just checking in--could you use any more help on this issue?

sanjuthomas commented 7 years ago

@sammefford thanks for checking. As you said, there are other ways to achieve what I wanted.