2

I am using Spring 1.3.3 and I am unable to use POST call for embedded object. Getting the following error while using POST call..

Request

curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{
  "student": {
    "address": {
         .....
         "zipcode": http://localhost:8082/zipcode/1,

     }
  },
  "id": 1,
  "zipcode": http://localhost:8082/zipcode/1,
  "name": "John"
 }' 'http://localhost:8082/student'

Response Error:

{
  "cause": {
    "cause": null,
    "message": "Unrecognized token 'http': was expecting ('true', 'false' or 'null')\n at [Source: org.apache.catalina.connector.CoyoteInputStream@4a12dfc; line: 3, column: 22]"
  },
  "message": "Could not read document: Unrecognized token 'http': was expecting ('true', 'false' or 'null')\n at [Source: org.apache.catalina.connector.CoyoteInputStream@4a12dfc; line: 3, column: 22]; nested exception is com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'http': was expecting ('true', 'false' or 'null')\n at [Source: org.apache.catalina.connector.CoyoteInputStream@4a12dfc; line: 3, column: 22]"
}

Address.java

@Embeddable
public class Address {
    private String street; 
    private String city; 
    private String state;
    // getters and setters

Student.java

@Entity 
@Table(name="Student") 
@SecondaryTable(name="Student_ADDRESS",
                pkJoinColumns=@PrimaryKeyJoinColumn(name="Student_ID"))
public class Student {
    @Id private int id;
    private String name;

    @Embedded
    @AttributeOverrides({
        @AttributeOverride(name="street", column=@Column(table="Student_ADDRESS")),
        @AttributeOverride(name="city", column=@Column(name="CITY", table="Student_ADDRESS")),
        @AttributeOverride(name="state", column=@Column(name="STATE", table="Student_ADDRESS")),
    })
    private Address address;
    private Zipcode zipcode;
//getters and setters

Zipcode.java

@Entity
public class Zipcode {
    @Id
    public int id;
    public String code;
}

How to save embedded object? Kindly provide your inputs.

1
  • kindly tell what is name of Embedded object here Commented Apr 2, 2017 at 15:24

1 Answer 1

2

It tells you that you should put "" around the urls.

curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{
  "student": {
    "address": {
         .....
         "zipcode": "http://localhost:8082/zipcode/1",

     }
  },
  "id": 1,
  "zipcode": "http://localhost:8082/zipcode/1",
  "name": "John"
 }' 'http://localhost:8082/student'
Sign up to request clarification or add additional context in comments.

1 Comment

if both associated objects exists then how we can create relation ,and put data inside composite table

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.