我尝试访问JSON响应时发生UnrecognizedPropertyException

时间:2013-12-16 10:04:15

标签: json

以下是代码段

public void testGetOfferbyID(OfferTestData data)抛出ClassNotFoundException,SQLException,HttpException,IOException     {

    String Request=gson.toJson(data.getOfferId());      
    System.out.println(Request);
    Long offerid=data.getOfferId();     
    int expectedResponseCode=data.getExpectedResponseCode();
    String OfferbyIdResponse=OfferUtilis.GetOfferByOfferId(offerid, expectedResponseCode);  
    System.out.println("Response::"+OfferbyIdResponse);     
    String Expected_offerid=gson.toJson(data.getOfferId());         
    System.out.println("ExpectedOfferId:"+Expected_offerid);
    OfferTestData actualoffer = mapper.readValue(OfferbyIdResponse, OfferTestData.class);
    System.out.println("ActualOfferId:"+actualoffer.getOfferId());  

回复如下:

{"offer":{"offer_id":123,"offer_type":"MSB","redemption_code":"SAMPLE_REDEMPTION_CODE","offer_program_id":1111,"redeem_start_date":"2013-12-10T23:49:19+05:30","redeem_end_date":"2013-12-15T23:49:19+05:30","offer_save_time":"45899-01-26T15:29:34+05:30","currency_code":"USD","value_issued":500,"value_used":0,"owner_id_type":"PAYPAL_ACCOUNT","owner_id":1111111111,"pin":123,"redeem_count":0,"delivery_channel_mode":"EMAIL","previous_owner_id_type":"PAYPAL_ACCOUNT","receiver_id_type":"PAYPAL_ACCOUNT","sender_id_type":"PAYPAL_ACCOUNT","vendor_id_type":"PAYPAL_ACCOUNT","time_created":"45899-01-26T15:27:55+05:30","time_updated":"45899-01-26T15:27:55+05:30"}}       

以下是我尝试从我的回复中提取offer_id时收到的错误消息。

FAILED: testGetOfferbyID(com.paypal.JINJOServ.offertestdata.OfferTestData@4e2b5fab)
org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "offer"     (Class com.paypal.JINJOServ.offertestdata.OfferTestData), not marked as ignorable

提供测试数据:

  @XmlRootElement(name = "offer")
  @XmlAccessorType(XmlAccessType.FIELD)
  @JsonInclude(Include.NON_NULL)
  public class OfferTestData    {

/** Unique internal offerId generated by the system. */
@XmlElement(name = "offer_id")
private Long offerId;

/** Indicates type of offer. */
@XmlElement(name = "offer_type")
private OfferType offerType;

  public Long getOfferId()
{
    return offerId;
}

public void setOfferId(Long offerId)
{
    this.offerId = offerId;
}

public OfferType getOfferType()
{
    return offerType;
}

public void setOfferType(OfferType offerType)
{
    this.offerType = offerType;
}

0 个答案:

没有答案