【问题标题】:How can I configure Spring Data to use the string version of an object when saving to Mongo DB?保存到 Mongo DB 时,如何配置 Spring Data 以使用对象的字符串版本?
【发布时间】:2015-09-29 12:59:11
【问题描述】:

我有一个代表人工制品的对象:

public class Artifact {

    private final URI location;

    public Artifact(URI location) {
        this.location = location;
    }
}

当我使用MongoTemplate 来保存它时,URI 会变成一个对象:

{ "location" : { "scheme" : "http", "authority" : "localhost:8080", "host" : "localhost", "port" : 8080, "path" : "/testFrontendURL", "schemeSpecificPart" : "//localhost:8080/testFrontendURL", "hash" : 331612143, "string" : "http://localhost:8080/testFrontendURL" }

但是,这只能由 URI 字符串表示:

{"location": "http://localhost:8080/testFrontendURL"}

如何配置 Spring Data 来执行此操作?

【问题讨论】:

    标签: java spring mongodb


    【解决方案1】:
    猜你喜欢
    • 2015-12-06
    • 2019-02-25
    • 1970-01-01
    • 2014-08-15
    • 2021-09-19
    • 1970-01-01
    • 2016-03-06
    • 2015-10-19
    • 1970-01-01
    相关资源
    最近更新 更多