How to map Set or List to array using jaxrs (resteasy) in Angular 5 app?

问题: I have the following java code/Object: @Entity @XmlRootElement @XmlAccessorType(XmlAccessType.NONE) public class Company implements java.io.Serializable { ... @...

问题:

I have the following java code/Object:

@Entity
@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
public class Company implements java.io.Serializable {

    ...

    @XmlElementWrapper(name="trips")
    @XmlElement(name = "trip")
    private Set<Trip> trips = new HashSet<Trip>(0); 

    ... 
}

Here are the relevant jars files: enter image description here

The response is json in the console:

"trips":{"trip":{"id":1,"name":"ABC"}}}}

As you can see the response doesn't include any brackets ("[]") which means the resteasy doesn't convert it to array, This behaviour causes me a lot of issue in the angular app. Is there a way to force the java/resteasy to convert to array so I can easily manipulate the array in the Angular app ?

What is the best practice to transform list to an Angular app ? I believe that the json should be something like:

 "trips":{[{"id":1,"name":"ABC"},{"id":2,"name":"XYZ"}]}

Thanks in advance.


回答1:

I solved this problem by loading the trips separately and not by using inner array inside the company object. This way I am able to get array which make my life easier inside the Angular app.

  • 发表于 2019-03-06 15:12
  • 阅读 ( 184 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除