2017-04-19 10 views
1

jsonの文字列をjavaのユーザー定義オブジェクトにキャストするときに、私は例外以下のgetingを助けてくれます。例外org.codehaus.jackson.map.exc.UnrecognizedPropertyExceptionを解決するには

org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "acknowledgedby" (Class com.xchange.model.XchangeOutboundMessage), not marked as ignorable 
at [Source: [email protected]; line: 1, column: 34] (through reference chain: com.xchange.model.XchangeOutboundMessage["acknowledgedby"]) 

また、私はStackOverflowの上ここに多くのリンクを発見し、すべてのは、モデルのフィールドに@JsonIgnore注釈のために推奨していますが、私はこれを無視することはできません。

public List getOutBoundMessageList(){ 
     List list=new ArrayList(); 
     ObjectMapper mapper = new ObjectMapper(); 
     XchangeOutboundMessage xchangeOutboundMessage=null; 
     String json1=null; 
     try { 

      cluster = Cluster.builder().addContactPoint(contactPoints).build(); 

      session = cluster.connect(keySpaceName); 

      cassandraOps = new CassandraTemplate(session); 
      String queryString="Select JSON * from XchangeOutboundMessage"; 
      ResultSet result = session.execute(queryString); 
      int i=0; 
      String json1=null; 
      for(Row row:result) { 
       json1 = row.getString(i); 
       xchangeOutboundMessage = mapper.readValue(json1, XchangeOutboundMessage.class); 
       list.add(xchangeOutboundMessage); 
       i++; 
      } 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
     return list; 
    } 
} 

Modelクラスのフィールドとゲッター、例外occuring

private String acknowledgedBy; 
public String getAcknowledgedBy() { 
     return acknowledgedBy; 
    } 
    public void setAcknowledgedBy(String acknowledgedBy) { 
     this.acknowledgedBy = acknowledgedBy; 
    } 
+1

Modelクラス全体を共有して問題を明確に理解しているとします。 –

答えて

0

あなたが原因ジャックのマッパーの例外を取得しているが、大文字と小文字が区別されセッター。 デフォルトでは、cassandraはすべてのカラム名をlowercaseにします。だからあなたのフィールド名(承認済み)とcassandra cassandraの列名(承認済み)が一致しない理由です。

設定方法で大文字と小文字を区別しない場合は、jacksonマッパーでキーを一致させることができます。

mapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true); 
関連する問題