Serialization of Mongo objects leaves a '_id' and '_class' field in the json. How can I turn that off?

Viewed 110

Serialization of Mongo objects leaves an _id and _class field in the json. I could live with _id but I would like to remove _class field from the JSON.

I have a Spring-Boot app reading JSON from a Mongo db.

How can I turn it off, so that only the objects explicit fields are saved into the Mongo json document (on the write)?

{
    "_id": {
        "$oid": "618da8804b421f7f5e1e756c"
    },
    ...
    "_class": "com.whatever.my.ApplicationObj"
}

NOTE1: _id is mentioned here as being a 'read-only' field:

NOTE2: _class is mentioned here also:

NOTE3: _id is mentioned here as being required.

Do I need a custom serializer?

0 Answers
Related