The solution based on @CamiloCrespo answers:
public static Document<String> toDocument(String id, Object value, ObjectMapper mapper) throws JsonProcessingException { return RawJsonDocument.create(id, mapper.writeValueAsString(value)); }
Keep in mind that you cannot use a simple pointer like ObjectMapper mapper = new ObjectMapper() , with Dropwizard .
You can get it from Environment#getObjectMapper() in the Application#run() method or use Jackson.newObjectMapper() for tests.
Usage example:
ObjectMapper mapper = Jackson.newObjectMapper(); User user = User.createByLoginAndName("login", "name"); bucket.insert(toDocument("123", user, mapper));
source share