_embedded没有出现在Spring的Json响应中

时间:2015-09-08 07:01:36

标签: spring spring-boot spring-data-rest spring-hateoas hal

我是春天新手。我有

Customer.java

body {
  font-family: 'Open Sans', Helvetica, Arial, sans-serif;
  color: #666666;
  font-size: 14px;
  line-height: 20px;
  padding: 0 !important;
  height: 2999px;
}
h1,
h2,
h3,
h4,
h5,
h6 {
  color: #454545;
  font-weight: 300;
  font-family: 'Open Sans', Helvetica, Arial, sans-serif;
  margin: 0 0 15px;
}
img {
  max-width: 100%;
  height: auto;
  vertical-align: middle;
  border: 0;
  -ms-interpolation-mode: bicubic;
}
.clear {
  clear: both;
}
.bold {
  font-weight: bold;
}
a {
  color: #1c1c1c;
  text-decoration: none;
}
a:hover {
  color: #7ab80e;
  text-decoration: none;
}
ul,
ol {
  padding: 0;
  margin: 0 0 10px 25px;
}


#main-nav{
    background: #2c2c2c;
    margin: 0 auto;
    border-bottom: 5px solid #cd2122;
    z-index: 12;
    position:relative;
}
#main-nav ul li {
  text-transform: uppercase;
  font-family: arial,Georgia, serif;
  font-size:12px;
  position: relative;
  display: inline-block;
  border:1px solid #222222;
  border-width:0 0 0 1px;
  float:left;
}
#main-nav ul li a {
  display: inline-block;

  color: #ddd;
  padding:12px;
  text-shadow:0 1px 1px #000;
  border-left:1px solid #383838;
  position: relative;
}

我的OrderItem.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);
   }
}

当我将hal-browser运行到

http://localhost:8080/api/v1/customers/1/cart 以前它正在返回

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>
   {
   }
}

但现在将spring的版本更改为4.2.0.RC3并将jackson版本保持为2.6.1。 _embedded没有进入json respose

显示为

{
  "_links": {
    "self": {
      "href": "http://localhost:8080/api/v1/customers/1/cart"
    }
  },
  "_embedded": {
    "orderItems": [
      {
  ....}]}

请告知。

0 个答案:

没有答案