2016-07-30 6 views
0

有効な市民のアドレスに対してJSONを返すRESTエンドポイントを呼び出そうとしています。nullストリームの入力ストリームからエンティティを読み取るときにエラーが発生しました

{ 
    "success":false, 
    "results":null, 
    "error":{ 
     "code":123, 
     "message":"Invalid Civic Address. Valid Example: 123 Main St, My City...", 
     "details":[ 
     "The civic address submitted to the service contained an alphabetic character where a number was expected." 
     ] 
    } 
} 

:私はこのような、私は戻って戻って何かサービスを扱うことができない形式のリクエストを送信する場合は

{ 
    "success":true, 
    "results":[ 
     { 
     "civicnumberid":123456, 
     "civic_address_as_string":"123 Main Street, My City, My Municipality, My County", 
     "esri_point":{ 
      "x":12345.678, 
      "y":54321.012 
     } 
     } 
    ], 
    "error":null 
} 

:呼び出しが成功で、私は戻って、このような何かを得ます「結果」に注意してください。ヌル JAX-RS 2.0とJackson 2.5.1を使用してレスポンスを変換しようとしているときに、「入力ストリームからエンティティを読み取る際にエラーが発生しました」というエラーが表示されて失敗します。

defaultObjectMapper.configure(SerializationFeature.WRAP_ROOT_VALUE, true) 
    .configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true) 
    .configure(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS, true) 
    .configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true) 
    .configure(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT, true) 
    .configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true) 

マイResponseObject JAXBオブジェクトです::

public class ResponseObject 
    implements Serializable 
{ 

    private final static long serialVersionUID = 1L; 
    protected Boolean success; 
    @XmlElement(nillable = true) 
    protected List<Result> results; 
    @XmlElement(nillable = true) 
    protected Error error; 

でき「結果」:ヌルが正常に処理されたり、私が戻るために、サービスプロバイダで動作するはずです。ここに私の現在ObjectMapperの設定です空のリスト?

答えて

0

nullの結果が問題であると仮定するのは間違っていました。

<xs:complexType name="Error"> 
    <xs:sequence> 
     <xs:element minOccurs="0" name="code" type="xs:int" /> 
     <xs:element minOccurs="0" name="message" nillable="true" type="xs:string" /> 
     <xs:element minOccurs="0" name="details" nillable="true" 
      type="q1:ArrayOfstring" xmlns:q1="http://schemas.microsoft.com/2003/10/Serialization/Arrays" /> 
    </xs:sequence> 
</xs:complexType> 

...次JAXBタイプの結果:

public class Error { 

    protected Integer code; 
    @XmlElement(nillable = true) 
    protected String message; 
    @XmlElement(nillable = true) 
    protected ArrayOfstring details; 

しかし、私はこれにスキーマを変更する場合:

<xs:complexType name="Error"> 
    <xs:sequence> 
     <xs:element minOccurs="0" name="code" type="xs:int" /> 
     <xs:element minOccurs="0" name="message" nillable="true" type="xs:string" /> 
     <!-- 
     <xs:element minOccurs="0" name="details" nillable="true" 
      type="q1:ArrayOfstring" xmlns:q1="http://schemas.microsoft.com/2003/10/Serialization/Arrays" /> 
      --> 
     <xs:element minOccurs="0" name="details" maxOccurs="unbounded" nillable="true" type="xs:string" /> 
    </xs:sequence> 
</xs:complexType> 
エラーJAXBタイプは以下のスキーマ型を使用して定義されました

...次のJAXBタイプが機能します。

public class Error { 

    private final static long serialVersionUID = 1L; 
    protected Integer code; 
    @XmlElement(nillable = true) 
    protected String message; 
    @XmlElement(nillable = true) 
    protected List<String> details; 
関連する問題