3

I am using spring-data-rest-webmvc:2.5.6.RELEASE. My application uses auto configuration to expose all endpoints simple I didn't provide any custom configuration. Consider the following domain classes

Order.java

public class Order {

    @Id @GeneratedValue//
    private Long id;
    @ManyToOne(fetch = FetchType.LAZY)//
    private Person creator;
    private String type;

    public Order(Person creator) {
        this.creator = creator;
    }

    // getters and setters
}

Person.java

pubic class Person {

    @Id @GeneratedValue private Long id;

    @Description("A person's first name") //
    private String firstName;

    @Description("A person's last name") //
    private String lastName;

    @Description("A person's siblings") //
    @ManyToMany //
    private List<Person> siblings = new ArrayList<Person>();

    @ManyToOne //
    private Person father;

    @Description("Timestamp this person object was created") //
    private Date created;

    @JsonIgnore //
    private int age;

    private int height, weight;
    private Gender gender;

    // ... getters and setters
}

I am using a following curl command to POST a order

    curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{ \ 
   "creator": { \ 
     "firstName": "John", \ 
     "lastName": "Smith", \ 
     "age": 1 \ 
   }
 }' 'http://localhost:8080/orders'

The server throws 500 Internal Server Error. Because order.creator=null in hibernate insert query. But if I modify my curl request body as follows

curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{ \ "creator": "http://localhost:8080/creators/1" }' http://localhost:8080/orders'

the server returns 200 as expected. But I don't want to use the 2nd curl command, since my existing application requests with nested/expanded json entity in request body.

Is there any configuration exists in spring-data-rest to make the 1st curl command successfull? or

Is this an issue with spring-data-rest?

Achaius
  • 5,904
  • 21
  • 65
  • 122
  • http://stackoverflow.com/a/11748184/4361743 – karman Jan 05 '17 at 13:26
  • Hi, I am using jackson-2.x. I also tried configuring object mapper as follows. objectMapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false); But still found the same issue. Is there any other configuration exists in Jackson2 – Achaius Jan 05 '17 at 13:54
  • Firstly you already have a question on this subject and which has an open bounty and where people (like myself) are spending (unfortunately without the full facts probably now wasting) ) their time trying to help you so you should therefore close this question and update the original question with the new information. http://stackoverflow.com/questions/40990415/spring-data-rest-integration-test-fails-with-simple-json-request – Alan Hay Jan 06 '17 at 14:17
  • Answered on your other question: http://stackoverflow.com/a/41507949/1356423 – Alan Hay Jan 06 '17 at 14:44
  • Please do not ask the same question repeatedly. This is regarded as noise on Stack Overflow. If your question is closed as unanswerable or did not attract responses, then the first thing to do is to *improve the question*; some guidance for this is [given here](http://stackoverflow.com/help/how-to-ask). Low-quality or unanswerable questions will typically be closed, but can be re-opened if improved or clarified (as appropriate). – Matt Jan 08 '17 at 11:21

0 Answers0