Search code examples
javamongodbjerseyjax-rsmorphia

Including Morphia for JSON-to-object mapping with JAX-RS+Jersey


I'm setting up a REST route with JAX-RS+Jersey that consumes a JSON object. This JSON object is special because one of the fields it contains is associated with a Morphia entity. Is there a way to integrate Morphia's object-mapping with Jackson so that I can deserialize my object?

Example:

Incoming JSON object in request body:

{
    operation: "CREATE",
    document: {  // This object is a Morphia entity
        "name": "Bob"
        "age": 18
    }
}

should be mapped to

POJO:

public class JSONContainer {
    String operation;
    Document document; // This object is a Morphia entity
}

Solution

  • Check out this github project titled "morphia_jackson_polymorphism_example"