I am new to spring. I have
Customer.java
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OrderColumn;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.hibernate.annotations.Type;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import com.vividsolutions.jts.geom.Geometry;
@Entity
public class Customer
{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public long id;
@Column(unique=true)
@NotNull
@Size(min = 1)
public String username;
static final int MAX_NAME_LENGTH = 255;
@Column(length=MAX_NAME_LENGTH)
@Size(min = 1, max=MAX_NAME_LENGTH)
@NotNull
public String name;
static final int MAX_EMAIL_LENGTH = 64;
@Column(length=MAX_EMAIL_LENGTH)
@Size(min = 1, max=MAX_EMAIL_LENGTH)
@NotNull
public String email;
static final int MAX_MOBILE_LENGTH = 16;
@Column(length=MAX_MOBILE_LENGTH)
@Size(min = 1, max=MAX_MOBILE_LENGTH)
@NotNull
public String mobile;
static final int MAX_ADDRESS_LENGTH = 512;
@Column(length=MAX_ADDRESS_LENGTH)
@NotNull
@Size(min = 1, max=MAX_ADDRESS_LENGTH)
public String address;
@Column(unique=true)
@Type(type = "org.hibernate.spatial.GeometryType")
public Geometry location;
@OneToMany(targetEntity=OrderItem.class, fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@OrderColumn(nullable = false)
public List<OrderItem> cart = new ArrayList<>();
@OneToMany(mappedBy="customer")
public List<Order> orders;
public static interface Repository extends PagingAndSortingRepository<Customer, Long>
{
Customer findByUsername(@Param("username") String username);
}
}
And my OrderItem.java
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.validation.constraints.NotNull;
import org.springframework.data.repository.PagingAndSortingRepository;
@Entity
public class OrderItem
{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public long id;
@ManyToOne
@NotNull
public Product product;
@NotNull
public int quantity;
public static interface Repository extends PagingAndSortingRepository<OrderItem, Long>
{
}
}
When i run the hal-browser to
http://localhost:8080/api/v1/customers/1/cart Previously It was returning the
{
"_links": {
"self": {
"href": "http://localhost:8080/api/v1/customers/1/cart"
}
},
"_embedded": {
"orderItems": [
{
....}]}
But now after changing the version of spring to 4.2.0.RC3 and keeping jackson version as 2.6.1. _embedded is not coming in the json respose
its showing like
{
"_links": {
"self": {
"href": "http://localhost:8080/api/v1/customers/1/cart"
}
}
}
Kindly advise.