1

I have Hotel entity and it has another object called Location.

@Entity
public class Hotel implements Serializable {
      private static final long serialVersionUID = 1L;
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private Long id;
      String name;
      @OneToOne(fetch=FetchType.LAZY)
      @JoinColumn(name="LOC_ID")
      Location location;
      //GETTER SETTER
  }

Location object like that:

@Entity
public class Location implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name="LOC_ID")
    private Long id;

    String name;

    public Location() {
    }

    public Location(String name) {
        this.name = name;
    }

    public String getName()
    {
        return name;
    }
    public void setName(String name)
    {
        this.name = name;
    }
}

I can send Location object to server ({"name":"MyNewLoc"}). I can send Hotel object to server with only name it's also ok ({"name":"NewHotel"}).

But when I try to send hotel object with name and Location attribute ({"name":"New Hotel","location":{"name":"MyNewLoc"}}), I get 400 POST error and this response;

exception:"org.springframework.http.converter.HttpMessageNotReadableException"

message:"Could not read JSON: Template must not be null or empty! (through reference chain: org.maskapsiz.sosyalkovan.domain.Hotel["location"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Template must not be null or empty! (through reference chain: org.maskapsiz.sosyalkovan.domain.Hotel["location"])"

I am using jackson-mapper-asl 1.9.13 and Spring boot.

1

1 Answer 1

3

I added @RestResource(exported = false) and it works for me.

@Entity
@RestResource(exported = false)
public class Location implements Serializable {
}
Sign up to request clarification or add additional context in comments.

Comments

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.