0

I have below Pojo class for the mongo entity

public class Product {
    @BsonProperty("_id")
    @BsonId
    private ObjectId id;
    private String name;
    private float price;
    private String description;
}

when I fetch the mongo result as per the below code

var item = Flowable.fromPublisher(this.repository.getCollection("product", Product.class).find()).blockingIterable();

The id id mapped something like this

enter image description here

However, in the database the id is something like this

enter image description here

How do I map this id in the correct way, I am using Micronaut framework with java 15

San Jaisy
  • 15,327
  • 34
  • 171
  • 290
  • https://docs.mongodb.com/manual/reference/bson-types/#objectid looks correct to me. If you want to achieve the same, i gues you shoult try that: https://www.javadoc.io/doc/org.mongodb/bson/2.7.2/org/bson/types/ObjectId.html#toStringMongod() – IEE1394 Dec 06 '20 at 21:11
  • value.toString() does work for me. – San Jaisy Dec 07 '20 at 02:49

1 Answers1

-1

You can add simple getter:

@JsonGetter
public String getObjectId() {
  return id.toString();
}
TOUDIdel
  • 1,322
  • 14
  • 22