• <small id='32dhF'></small><noframes id='32dhF'>

    <legend id='32dhF'><style id='32dhF'><dir id='32dhF'><q id='32dhF'></q></dir></style></legend>
      <bdo id='32dhF'></bdo><ul id='32dhF'></ul>

      1. <i id='32dhF'><tr id='32dhF'><dt id='32dhF'><q id='32dhF'><span id='32dhF'><b id='32dhF'><form id='32dhF'><ins id='32dhF'></ins><ul id='32dhF'></ul><sub id='32dhF'></sub></form><legend id='32dhF'></legend><bdo id='32dhF'><pre id='32dhF'><center id='32dhF'></center></pre></bdo></b><th id='32dhF'></th></span></q></dt></tr></i><div id='32dhF'><tfoot id='32dhF'></tfoot><dl id='32dhF'><fieldset id='32dhF'></fieldset></dl></div>

        <tfoot id='32dhF'></tfoot>
      2. 如何在没有 _class 属性的情况下将 spring 数据与 couchbase 一起使用

        时间:2024-08-23
        • <bdo id='npkVk'></bdo><ul id='npkVk'></ul>
        • <small id='npkVk'></small><noframes id='npkVk'>

            1. <legend id='npkVk'><style id='npkVk'><dir id='npkVk'><q id='npkVk'></q></dir></style></legend>
              • <i id='npkVk'><tr id='npkVk'><dt id='npkVk'><q id='npkVk'><span id='npkVk'><b id='npkVk'><form id='npkVk'><ins id='npkVk'></ins><ul id='npkVk'></ul><sub id='npkVk'></sub></form><legend id='npkVk'></legend><bdo id='npkVk'><pre id='npkVk'><center id='npkVk'></center></pre></bdo></b><th id='npkVk'></th></span></q></dt></tr></i><div id='npkVk'><tfoot id='npkVk'></tfoot><dl id='npkVk'><fieldset id='npkVk'></fieldset></dl></div>
                <tfoot id='npkVk'></tfoot>

                    <tbody id='npkVk'></tbody>
                • 本文介绍了如何在没有 _class 属性的情况下将 spring 数据与 couchbase 一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  有没有一种简单的方法可以将 spring data couchbase 与没有 _class 属性的文档一起使用?在沙发上,我的 sampledata 存储桶中有类似的东西:

                  Is there a simple way to use spring data couchbase with documents that do not have _class attribute? In the couchbase I have something like this in my sampledata bucket:

                  {
                    "username" : "alice", 
                    "created" : 1473292800000,
                    "data" : { "a": 1, "b" : "2"},
                    "type" : "mydata"
                  }
                  

                  现在,有什么方法可以定义从这种文档结构到 Java 对象的映射(注意 _class 属性丢失并且无法添加),反之亦然,以便我得到所有(或大多数) 来自 spring couchbase 数据的自动功能?

                  Now, is there any way to define mapping from this structure of document to Java object (note that _class attribute is missing and cannot be added) and vice versa so that I get all (or most) automagical features from spring couchbase data?

                  类似:如果 type 字段的值为mydata",则使用类 MyData.java.因此,当执行查找而不是自动添加 AND _class = "mydata" 到生成的查询时添加 AND type = "mydata".

                  Something like: If type field has value "mydata" use class MyData.java. So when find is performed instead of automatically adding AND _class = "mydata" to generated query add AND type = "mydata".

                  推荐答案

                  Spring Data 通常需要 _class 字段来知道在反序列化时要实例化回什么.

                  Spring Data in general needs the _class field to know what to instantiate back when deserializing.

                  通过覆盖 AbsctractCouchbaseDataConfiguration 中的 typeKey() 方法,在 Spring Data Couchbase 中使用与 _class 不同的字段名称相当容易.

                  It's fairly easy in Spring Data Couchbase to use a different field name than _class, by overriding the typeKey() method in the AbsctractCouchbaseDataConfiguration.

                  但默认情况下它仍然需要一个完全限定的类名

                  解决这个问题需要更多的工作:

                  Getting around that will require quite a bit more work:

                  1. 您需要按照 DefaultCouchbaseTypeMapper 的模型实现自己的 CouchbaseTypeMapper.在 super(...) 构造函数中,您需要提供一个附加参数:TypeInformationMapper 列表.默认实现没有显式提供一个,因此使用了 SimpleTypeInformationMapper,它是放置 FQN 的那个.
                  2. 还有一个可配置的替代实现,因此您可以通过 Map 将特定类别名为更短的名称:ConfigurableTypeInformationMapper...
                  3. 因此,通过将 ConfigurableTypeInformationMapper 与特定类所需的别名 + SimpleTypeInformationMapper 放在列表中(如果您序列化了您没有'不提供别名),你可以实现你的目标.
                  4. typeMapperMappingCouchbaseConverter 中使用,不幸的是,您还需要扩展它(只是为了实例化您的 typeMapper 而不是默认.
                  5. 一旦你有了它,再次覆盖配置以返回使用自定义 CouchbaseTypeMapper 的自定义 MappingCouchbaseConverter 实例(mappingCouchbaseConverter() 方法).
                  1. You'll need to implement your own CouchbaseTypeMapper, following the model of DefaultCouchbaseTypeMapper. In the super(...) constructor, you'll need to provide an additional argument: a list of TypeInformationMapper. The default implementation doesn't explicitly provide one, so a SimpleTypeInformationMapper is used, which is the one that puts FQNs.
                  2. There's an alternative implementation that is configurable so you can alias specific classes to a shorter name via a Map: ConfigurableTypeInformationMapper...
                  3. So by putting a ConfigurableTypeInformationMapper with the alias you want for specific classes + a SimpleTypeInformationMapper after it in the list (for the case were you serialize a class that you didn't provide an alias for), you can achieve your goal.
                  4. The typeMapper is used within the MappingCouchbaseConverter, which you'll also need to extend unfortunately (just to instantiate your typeMapper instead of the default.
                  5. Once you have that, again override the configuration to return an instance of your custom MappingCouchbaseConverter that uses your custom CouchbaseTypeMapper (the mappingCouchbaseConverter() method).

                  这篇关于如何在没有 _class 属性的情况下将 spring 数据与 couchbase 一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何覆盖 Spring Data CrudRepository 上的删除方法? 下一篇:Spring Data Mongo + 延迟加载 + REST Jackson

                  相关文章

                • <tfoot id='H1bTT'></tfoot>
                  <i id='H1bTT'><tr id='H1bTT'><dt id='H1bTT'><q id='H1bTT'><span id='H1bTT'><b id='H1bTT'><form id='H1bTT'><ins id='H1bTT'></ins><ul id='H1bTT'></ul><sub id='H1bTT'></sub></form><legend id='H1bTT'></legend><bdo id='H1bTT'><pre id='H1bTT'><center id='H1bTT'></center></pre></bdo></b><th id='H1bTT'></th></span></q></dt></tr></i><div id='H1bTT'><tfoot id='H1bTT'></tfoot><dl id='H1bTT'><fieldset id='H1bTT'></fieldset></dl></div>
                    <bdo id='H1bTT'></bdo><ul id='H1bTT'></ul>

                • <small id='H1bTT'></small><noframes id='H1bTT'>

                    <legend id='H1bTT'><style id='H1bTT'><dir id='H1bTT'><q id='H1bTT'></q></dir></style></legend>