user2732949
user2732949

Reputation: 1223

How can I configure Spring Data to use the string version of an object when saving to Mongo DB?

I've got an object that represents an Artefact:

public class Artifact {

    private final URI location;

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

When I use MongoTemplate to save this, the URI gets turned into an object:

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

But, this could just be represented by the URI string:

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

How can I configure Spring Data to do this?

Upvotes: 0

Views: 58

Answers (1)

Related Questions