2015-07-03 104 views
0

我使用球衣來創建json/xml REST api。但是我在Moxy遇到了一些奇怪的行爲。Jersey不正確地解析json long

當它大於某個值時,它似乎會切斷一段長長的java值。

我使用有問題的實體的主鍵是:871687120000007010,但如果我詢問我的API來進行測試,將出現以下情況:

http://i.stack.imgur.com/QbExD.png

注意,圖像顯示「EAN」(主鍵)已被切斷。 做一些測試它後,我發現了以下工作:

使用9223372036854775807作爲主鍵(64位有符號整數最大值)
產量:它已經被解析MOXY後9223372036854776000。這比一個64位的int整數還要高。

但投入9223372036854774807
息率9223372036854775000

好像圓高值高達1000的精度。

有沒有人知道這裏發生了什麼?

模型類:

import javax.persistence.Column; 
import javax.persistence.Entity; 
import javax.persistence.Id; 
import javax.persistence.ManyToMany; 
import javax.persistence.Table; 
import javax.xml.bind.annotation.XmlElement; 
import javax.xml.bind.annotation.XmlRootElement; 
import javax.xml.bind.annotation.XmlTransient; 
import java.util.Date; 
import java.util.HashSet; 
import java.util.Set; 

@Entity 
@Table(name = "CONNECTION") 
@XmlRootElement 
public class P4Connection { 

    @XmlElement 
    @Column(name = "SENDER", nullable = false) 
    private long sender; 

    @XmlElement 
    @Column(name = "RECEIVER", nullable = false) 
    private long receiver; 

    @Id 
    @XmlElement(type = Long.class) 
    @Column(name = "ID", nullable = false) 
    private long ean; 

    @XmlElement 
    @Column(name = "LAST_COLLECT") 
    private Date lastCollect; 

    @ManyToMany 
    private Set<Request> REQUEST; 

    public P4Connection() { 
     REQUEST = new HashSet<>(); 
    } 

    @XmlTransient 
    public long getSender() { 
     return sender; 
    } 

    public void setSender(long sender) { 
     this.sender = sender; 
    } 

    @XmlTransient 
    public long getReceiver() { 
     return receiver; 
    } 

    public void setReceiver(long receiver) { 
     this.receiver = receiver; 
    } 

    @XmlTransient 
    public long getEan() { 
     return ean; 
    } 

    public void setEan(long id) { 
     this.ean = id; 
    } 

    @XmlTransient 
    public Date getLastCollect() { 
     return lastCollect; 
    } 

    public void setLastCollect(Date lastCollect) { 
     this.lastCollect = lastCollect; 
    } 

    public Set<Request> getRequests() { 
     return REQUEST; 
    } 
} 

的API方法:

@GET 
@Path("/{ean}") 
@Produces(MediaType.APPLICATION_JSON) 
public P4Connection getConnection(@PathParam("ean") String ean, 
            @Context UriInfo uriInfo) throws AppException { 
    long eancode = parseEAN(ean, uriInfo); 
    Session session = Database.getInstance().getSession(); 
    Query query = session.createQuery("from P4Connection where ean = ?"); 
    query.setLong(0, eancode); 
    List connections = query.list(); 
    session.close(); 

    if (connections.size() != 1) 
     throw new AppException(ErrorCode.NOT_FOUND, uriInfo); 
    System.out.println(((P4Connection) connections.get(0)).getEan()); 
    return (P4Connection) connections.get(0); 
} 

當我呈現爲XML通過改變@Produces註釋

回答

0

不會發生這種情況原來,我的插件在我的瀏覽器中使用的是錯誤地顯示長值