Search code examples
javainheritancemorphia

How can I use Morphia to map a non-annotated pojo?


A class exists that I have no control over:

public class MyPerson {
  private String name;
  private int elevation;

  // getters and setters
}

I want to persist this person into Mongo, but I cannot alter this class definition with @Entity and other annotations.

I'd like the document in Mongo to look something akin to:

{ name : "You", elevation : 65 }

What's the best way to approach this? Converter? Extended class? Containing class?


Solution

  • The easiest way would be to just embed it in one you control, and can put the @Id on.