-
Notifications
You must be signed in to change notification settings - Fork 112
Closed
Description
Hi,
Would you consider using clever jackson annotations to reduce the amount of object mapper magic you need to get mongojack to work. Here's what I'm thinking:
First define an annotation like so:
@Retention(RetentionPolicy.RUNTIME)
@JacksonAnnotationsInside
@JsonSerialize(using = ObjectIdSerializer.class)
@JsonDeserialize(using = ObjectIdDeserializers.ToStringDeserializer.class)
@JsonProperty("_id")
@JsonInclude(JsonInclude.Include.NON_NULL)
public @interface SmartId {}Then use it like so:
public static class Example {
@SmartId
public String id;
public String text;
}
@Test
public void simpleTest() {
CodecRegistry provider = new JacksonCodecRegistry(
new ObjectMapper(), //Look no modules or anything!
db.getCodecRegistry(),
UuidRepresentation.UNSPECIFIED
);
var coll = db.withCodecRegistry(provider).getCollection("test", Example.class);
Example ex = new Example();
ex.text = "fiddlesticks";
var io = coll.insertOne(ex);
Example ex2 = coll.find().first();
}The neat thing about this is that I've only used an out-of-the-box CodecRegistry, and an out-of-the-box ObjectMapper. This is particularly valuable for projects that have complex ObjectMapper setups.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels