// We don't know what it is, serialise it
BsonObjectGenerator generator = new BsonObjectGenerator();
try {
objectMapper.writeValue(generator, value);
} catch (JsonMappingException e) {
throw new MongoJsonMappingException(e);
} catch (IOException e) {
throw new RuntimeException("Somehow got an IOException writing to memory", e);
}
return generator.getValue();
}