保存到Mongo DB时,如何配置Spring Data以使用对象的字符串版本?

时间:2015-09-29 12:59:11

标签: java spring mongodb

我有一个代表Artefact的对象:

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来执行此操作?