0

What is the way to consume a list of custom objects inside another custom object in JAX-RS CXF implementation? As an example my object looks like below

@POST
@Produces({MediaType.APPLICATION_JSON})
@Path("test")
public Response myMethod(MyCustomObject myCustomObject) {

Inside MyCustomObject it has a list of another custom object which reside inside this as an inner class

  public class MyCustomObject {

        private List<MyInner> innerObjects;

        public class MyInner {
            private String property;
            ....
        }
        ....
}

Request JSON object is passed as the POST body of the request. When I debug this I could get the MyCustomObject passed properly while I am sending the innerObjects list as null. But it seems its not picking this correctly when I have this array based structure there with a custom object. Additionally instead of this custom object array when I have a primitive type or a string based array the service works fine. How to deal with the above scenario.

Dilshan
  • 3,231
  • 4
  • 39
  • 50

1 Answers1

1

It is probably because of the inner class.

Similar question here

Not sure what mapper you use (cxf default is jettison but it is all configurable), but the case is probably similar.

Great explanation here

non-static inner classes (including anonymous ones) have set of hidden variables added by compiler, passed via (hidden) constructor. And as a consequence, do not have zero-argument ("default") constructor

Community
  • 1
  • 1
James Cube
  • 421
  • 3
  • 12
  • Yes its because of the inner classes. Making it a concrete class fixed it. Thank your for your answer. – Dilshan Mar 28 '15 at 04:34