title: Java MongoDb getting id as a timestamp but need the hexadecimal string
body: <p>I'm doing a CRUD for a collection named Schema and need to retrieve de _id as a hexadecimal string, but when i use the collection.find() i get the timestamp and date instead of the string.</p>
  <p><strong>I'm receving this structure:</strong></p>
  <pre><code>{
  &quot;_id&quot;: {
              &quot;timestamp&quot;: 1604689898,
              &quot;date&quot;: &quot;2020-11-06T19:11:38.000+00:00&quot;
          }
  }
  </code></pre>
  <p><strong>But i need something like this:</strong></p>
  <pre><code>{
  &quot;_id&quot;: &quot;5fa5a085a4b09b307d53ed57&quot;
  }
  </code></pre>
  <p><strong>Here are my configurations</strong></p>
  <p><strong>Pom.xml</strong></p>
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
      xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;parent&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
          &lt;version&gt;2.3.4.RELEASE&lt;/version&gt;
          &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
      &lt;/parent&gt;
      &lt;groupId&gt;co.com.itau&lt;/groupId&gt;
      &lt;artifactId&gt;crypto-mongodb-java-ms&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;name&gt;crypto-mongodb-java-ms&lt;/name&gt;
      &lt;description&gt;Microservice to save and read data from mongoDB using CSFLE&lt;/description&gt;
  
      &lt;properties&gt;
          &lt;java.version&gt;1.8&lt;/java.version&gt;
          &lt;version.fabric8-maven-plugin&gt;3.5.41&lt;/version.fabric8-maven-plugin&gt;
          &lt;swagger.version&gt;3.0.0&lt;/swagger.version&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-data-mongodb&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-validation&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.plugin&lt;/groupId&gt;
              &lt;artifactId&gt;spring-plugin-core&lt;/artifactId&gt;
              &lt;version&gt;2.0.0.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-data-rest&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-web-services&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.projectlombok&lt;/groupId&gt;
              &lt;artifactId&gt;lombok&lt;/artifactId&gt;
              &lt;optional&gt;true&lt;/optional&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.google.code.gson&lt;/groupId&gt;
              &lt;artifactId&gt;gson&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-devtools&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt; 
              &lt;groupId&gt;io.springfox&lt;/groupId&gt; 
              &lt;artifactId&gt;springfox-boot-starter&lt;/artifactId&gt; 
              &lt;version&gt;${swagger.version}&lt;/version&gt; 
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
              &lt;artifactId&gt;spring-cloud-starter-netflix-hystrix&lt;/artifactId&gt;
              &lt;version&gt;2.1.2.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
            &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.plugin&lt;/groupId&gt;
              &lt;artifactId&gt;spring-plugin-core&lt;/artifactId&gt;
              &lt;version&gt;2.0.0.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.mongodb&lt;/groupId&gt;
              &lt;artifactId&gt;mongodb-crypt&lt;/artifactId&gt;
              &lt;version&gt;1.0.1&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
              &lt;exclusions&gt;
                  &lt;exclusion&gt;
                      &lt;groupId&gt;org.junit.vintage&lt;/groupId&gt;
                      &lt;artifactId&gt;junit-vintage-engine&lt;/artifactId&gt;
                  &lt;/exclusion&gt;
              &lt;/exclusions&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
      
      &lt;profiles&gt;
          &lt;profile&gt;
              &lt;id&gt;openshift&lt;/id&gt;
              &lt;build&gt;
                  &lt;plugins&gt;
                      &lt;plugin&gt;
                          &lt;groupId&gt;io.fabric8&lt;/groupId&gt;
                          &lt;artifactId&gt;fabric8-maven-plugin&lt;/artifactId&gt;
                          &lt;version&gt;${version.fabric8-maven-plugin}&lt;/version&gt;
                          &lt;executions&gt;
                              &lt;execution&gt;
                                  &lt;id&gt;fmp&lt;/id&gt;
                                  &lt;phase&gt;package&lt;/phase&gt;
                                  &lt;goals&gt;
                                      &lt;goal&gt;resource&lt;/goal&gt;
                                      &lt;goal&gt;build&lt;/goal&gt;
                                  &lt;/goals&gt;
                              &lt;/execution&gt;
                          &lt;/executions&gt;
                          &lt;configuration&gt;
                              &lt;generator&gt;
                                  &lt;config&gt;
                                      &lt;spring-boot&gt;
                                          &lt;fromMode&gt;isTag&lt;/fromMode&gt;
                                          &lt;from&gt;redhat-openjdk18-openshift:1.2&lt;/from&gt;
                                      &lt;/spring-boot&gt;
                                  &lt;/config&gt;
                              &lt;/generator&gt;
                          &lt;/configuration&gt;
                      &lt;/plugin&gt;
                  &lt;/plugins&gt;
              &lt;/build&gt;
          &lt;/profile&gt;
      &lt;/profiles&gt;
  
  &lt;/project&gt;
  
  </code></pre>
  <p><strong>MongoClient configuration</strong></p>
  <pre class="lang-java prettyprint-override"><code>CodecRegistry pojoCodecRegistry = fromProviders(PojoCodecProvider.builder().automatic(true).build());
          CodecRegistry codecRegistry = fromRegistries(MongoClientSettings.getDefaultCodecRegistry(), pojoCodecRegistry);
          
          MongoClient mongoAux = MongoClients.create(MongoClientSettings.builder()
                  .applyConnectionString(new ConnectionString(connectionString))
                  .codecRegistry(codecRegistry)
                  .build());
          
          return mongoAux;
  
  </code></pre>
  <p><strong>Schema Model</strong></p>
  <pre class="lang-java prettyprint-override"><code>@Data
  @AllArgsConstructor
  @NoArgsConstructor
  public class Schema {
      
      @JsonProperty(&quot;_id&quot;)
      @SerializedName(&quot;_id&quot;)
      public ObjectId id;
  
      public String db;
      
      public String collection;
      
      public Document schema;
  }
  </code></pre>
  <p>** Repository **</p>
  <pre class="lang-java prettyprint-override"><code>@Repository
  public class SchemaMongoRepository implements SchemaRepository{
  
  
      @Value(&quot;${mongodb.schema.db}&quot;)
      private String mongoDatabase;
  
      @Value(&quot;${mongodb.schema.collection}&quot;)
      private String mongoCollection;
      
      
      private static final Logger logger = LoggerFactory.getLogger(SchemaMongoRepository.class);
  
      @Autowired
      private MongoClient mongoClient;
      
      @Autowired
      private DataKey datakey;
      
      private MongoCollection&lt;Schema&gt; schemaCollection;
      
      @PostConstruct
      void init() {
          schemaCollection = mongoClient.getDatabase(mongoDatabase).getCollection(mongoCollection, Schema.class);
      }
  
      @Override
      public List&lt;Schema&gt; getSchemas() {
      
          List&lt;Schema&gt; schemaList = new ArrayList&lt;Schema&gt;();
          FindIterable&lt;Schema&gt; result = schemaCollection.find();
          
          for(Schema currentSchema: result) {
              schemaList.add(currentSchema);
          }
          return schemaList;
      }
  }
  </code></pre>