2017-12-21 7 views
1

pact-jvm-consumerのcloseArrayに問題があります。Pact JVM closeArray

このようにJsonが与えられた場合、 "DslPart imeiResults = new PactDslJsonBody()" - ステートメントがどのように構築されますか。

{ 
    "Car": { 
    "Price": 123,  
    "Features": [ 
     "rain sensor", 
     "cruise control" 
    ], 
    "Id": "6500" 
    } 
} 

私はこのように試してみました:

DslPart etaResults = new PactDslJsonBody() 
      .object("Car") 
       .integerType("Price",123) 
       .array("Features") 
        .stringValue("rain sensor") 
        .stringValue("cruise control") 
       .closeArray() 
       .stringValue("Id","6500") 
      .closeObject() 
      .asBody(); 

しかし、それは動作しません。あなたは.closeArray(後に何かを持っていることはできませんので、例えば.closeArray())、PactDslJsonBodyしかしDslPartを返しませんか?私はそれを取得しない、誰かが正しい方法を行う方法のコードを表示することができますか?

答えて

0

closeArrayの後にstringValueが機能しないと思いますか?

悲しいことに、array関数を使用して配列を作成すると、実際にはcreates a new PactDslJsonArray and when closing it, there's no way for that class to know what the parent is, hence it just returns the common superclass of DslPartという混乱を招く可能性があります。何が行われる必要があるかは、asBody機能を使用してPactDslJsonBodyに戻ってDslPartにキャストされます。より良い経験をしようとする

DslPart etaResults = new PactDslJsonBody() 
    .object("Car") 
     .integerType("Price",123) 
     .array("Features") 
      .stringValue("rain sensor") 
      .stringValue("cruise control") 
     .closeArray() 
     .asBody() 
     .stringValue("Id","6500") 
    .closeObject(); 

今、私たちはこの混乱であることを知って、hence why we started working on a new DSL using Java 8's Lambda functions:だから、あなたの例は次のようになります。希望が役立ちます。

+0

いいえ、私はその例がうまくいくと思います。しかし、今私は再び詰まっています。あなたは、このJSONからDslPartの作成を支援:カリフォルニア州 { "インベントリ":[ { "カー":{ "ギアボックス": "のProductId"、 "自動":30212 }、 "カメラ" :{ "EndPrice":1235、 "条件":[ を "FaultyCasing" "FaultyButtons"]、 "ModelId": "650" } } ]、 "IsSuccess":真、 "情報": "OK" } –

+0

あなたは何を持っているのですか?私はあなたの仕事を熱心にしていません。実際の質問をお試しください。新しい質問をすべて始める方が良いかもしれません。 –

関連する問題