2

I have two JPA Entities (Patient and Clinic) with OneToMany ManyToOne relationship. I would like to return the data in JSON format (currently with org.apache.cxf.jaxrs.provider.JSONProvider). Below is a patient info and its associated clinic. However, it returns all fields for clinic. How could I just return primary key/id (@Id) for the clinic?

{
    "Patient": {
        "age": 0,
        "clinic": {
            "address": "long address here",
            "otherKeys": "other values",
            "id": 5
        },
        "ic": "010101",
        "id": 12,
        "name": "Patient 01"
    }
}
Lee Chee Kiam
  • 11,450
  • 10
  • 65
  • 87
  • See if this thread gives you some pointers - http://stackoverflow.com/questions/5455014/ignoring-new-fields-on-json-objects-using-jackson. Basically, try to provide your class level fields some annotation that will make JSONProvider ignore those fields. – legendofawesomeness Feb 16 '13 at 00:41
  • The `@JsonIgnore*` annotation is only for Jackson. I have tried with `org.codehaus.jackson.jaxrs.JacksonJsonProvider` before your suggestion, but it can't generate json data successfully like `org.apache.cxf.jaxrs.provider.JSONProvider` (failed with recursive issue). I tried to look at CXF api doc but can't find similar annotation/way like Jackson... – Lee Chee Kiam Feb 16 '13 at 00:59
  • Have you looked at using EclipseLink MOXy? It recently added support for mapping your objects to JSON: http://wiki.eclipse.org/EclipseLink/Examples/MOXy#Working_with_JSON_.28NEW_in_2.4.29 – Brian Vosburgh Feb 18 '13 at 16:52

0 Answers0