2013-06-24 57 views
1

鑑於下面的類:位置導致錯誤

@XmlSeeAlso({A.class, B.class}) 
@XmlDiscriminatorNode("@type") 
public abstract class Base implements Serializable { 
} 

A(和類似B)是:

@XmlDiscriminatorValue("A") 
public class A extends Base { 
    private String foo; 
    // constructor, getter, setter 
} 

包裝紙兩種類型的List<Base>包含對象會導致對此示例JSON:

{ 
    "list": [ 
    { 
     "@type": "A", 
     "bar": 123 
    }, 
    { 
     "@type": "A", 
     "bar": 789 
    }, 
    { 
     "@type": "B", 
     "foo": "sddadad" 
    }, 
    { 
     "@type": "B", 
     "foo": "ttf4eg4gf sd" 
    }, 
    { 
     "@type": "A", 
     "bar": 465 
    } 
    ] 
} 

現在爲止t其中我的問題踢:當@type財產移出了「第一」的位置,解組失敗:

{ 
    "bar" : 123, 
    "@type" : "A" 
} 

Exception Description: Missing class indicator field from database row [UnmarshalRecordImpl()].

這是一個預期的行爲?我是否必須確保@type聲明始終是「第一」?

我正在使用EclipseLink 2.5.1.v20130619-ffd088c每晚構建。

回答

1

當在解組器中指定UnmarshallerProperties.JSON_ATTRIBUTE_PREFIX時,當前EclipseLink JAXB (MOXy)要求具有屬性前綴的密鑰出現在沒有密鑰的位置。我已打開以下擴展請求(請參閱下面的鏈接),您可以使用它來跟蹤我們在此問題上的進度。

解決方法

只有當UnmarshallerProperties.JSON_ATTRIBUTE_PREFIX屬性設置出現此問題。當它沒有設置時,MOXy可以解組以下沒有任何問題:

{ 
    "bar" : 123, 
    "type" : "A" 
}