title: Using ObjectId as String in Java (Manual reference) with spring-data mongodb
body: <p>In MongoDB documentation they suggest to use ObjecId for manual references.
  please see  <a href="https://docs.mongodb.com/manual/reference/database-references/#document-references" rel="nofollow noreferrer">https://docs.mongodb.com/manual/reference/database-references/#document-references</a></p>
  <pre><code>original_id = ObjectId()
  
  db.places.insert({
      &quot;_id&quot;: original_id,
      &quot;name&quot;: &quot;Broadway Center&quot;,
      &quot;url&quot;: &quot;bc.example.net&quot;
  })
  
  db.people.insert({
      &quot;name&quot;: &quot;Erin&quot;,
      &quot;places_id&quot;: original_id,
      &quot;url&quot;:  &quot;bc.example.net/Erin&quot;
  })
  </code></pre>
  <p>I'm using <strong>spring-data-mongodb</strong> and what I'm looking for is to have a <em>People</em> class defined like this:</p>
  <pre><code>@Document
  public class People {
  
      private String name;
      @Reference // or any Annotation to convert an ObjectId to a String
      private String placesId; 
      private String url;
  }
  </code></pre>
  <p>How to have a &quot;places_id&quot; as ObjectId in mongoDB but mapped to a String in our POJO ?</p>
  <p>I was expecting to have an annotation like <strong>@Reference</strong> but it seems to not be implemented.</p>
  <p>I don't understand why we don't have this kind of annotation in spring-data-mongodb. I don't want to implement an explicit converter like suggested in <a href="https://docs.spring.io/spring-data/mongodb/docs/current/reference/html/#mapping-explicit-converters" rel="nofollow noreferrer">spring documentation</a> for all documents that use manual references.
  Maybe it's not the right approach.</p>
  <p>Did I miss something ?</p>
  <p><strong>UPDATE :</strong></p>
  <p>I like the idea to have a POJO using only String instead of ObjectId.  Let's say I've got a class <strong>Place</strong> like this :</p>
  <pre><code>@Document
  public class Place {
    @Id
    private String id;
    private String name;
  }
  </code></pre>
  <p><code>place.getId()</code> will be a String but <code>people.getPlaceId()</code> will be an ObjectId.  I want to avoid this unnecessary mapping.</p>