Java MongoDb getting id as a timestamp but need the hexadecimal string

The problem you face is ObjectId becomes extended (Deserialized). we make it serialization.Add this dependency in pom


Add the following method in main class.

public Jackson2ObjectMapperBuilderCustomizer customizer()
    return builder -> builder.serializerByType(ObjectId.class,new ToStringSerializer());

This will give you expected output.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top