2017-08-27 13 views
1

私は現在、MarkLogic POJOデータバインディングインターフェイスを使用しています。 POJOをMarkLogicに書くことができます。今私はそれらのPOJOを検索し、検索結果を取得したいと思います。私は以下の指示に従っています:https://docs.marklogic.com/guide/java/binding#id_89573しかし、検索結果は正しいオブジェクトを返すようには見えません。私はJSONMappingExceptionを取得しています。MarkLogic POJOデータバインディングインターフェイス:POJO検索を実行する際のJSONMappingException

HashMap<String, MatchedPropertyInfo> matchedProperties = new HashMap<String, MatchedPropertyInfo>(); 
    PropertyMatches PM = new PropertyMatches(123,"uri/prefix/location2", "uri/prefix", 1234,0,"/aKey","/aLocation",true,matchedProperties); 
    MatchedPropertyInfo MPI1 = new MatchedPropertyInfo("matched/property/uri1", "matched/property/key1", "matched/property/location1", true,"ValueMatch1", 12, 1*1.0/3, true); 
    MatchedPropertyInfo MPI2 = new MatchedPropertyInfo("matched/property/uri2", "matched/property/key2", "matched/property/location2", true,"ValueMatch2", 14, 1.0/2.0, true); 
    PM.getMatchedProperties().put("matched/property/prefix/location1", MPI1); 
    PM.getMatchedProperties().put("matched/property/prefix/location2", MPI2); 

    PojoRepository myClassRepo = client.newPojoRepository(PropertyMatches.class, Long.class); 
    myClassRepo.write(PM); 

    PojoQueryBuilder qb = myClassRepo.getQueryBuilder(); 
    PojoPage<PropertyMatches> matches = myClassRepo.search(qb.value("uri", "uri/prefix/location2"),1); 
    if (matches.hasContent()) { 
     while (matches.hasNext()) { 
      PropertyMatches aPM = matches.next(); 
      System.out.println(" " + aPM.getURI()); 
     } 
    } else { 
     System.out.println(" No matches"); 
    } 

PropertyMatches(PM)オブジェクトは、MarkLogicデータベースに正常に書き込まれています。このクラスには、というメンバーが含まれており、これは"uri/prefix/location2"で始まります。上記の例ではmatches.hasContent()がtrueを返します。ただし、エラーが発生しますPropertyMatches aPM = matches.next();

答えて

2

MarkLogicでPOJOを検索してJavaプログラムに読み込むには、POJOに空のコンストラクタが必要です。この場合PropertyMatchespublic PropertyMatches(){}で、MatchedPropertyInfoはpublic MatchedPropertyInfo(){}

0

ありがとうございます。あなたが見つけた回答を投稿してください。いくつかのドキュメント参照を追加するだけで、このトピックについてはここで説明します:http://docs.marklogic.com/guide/java/binding#id_54408https://docs.marklogic.com/javadoc/client/com/marklogic/client/pojo/PojoRepository.htmlです。

コンサルタクタに複数のパラメータを設定することもできます。ジャクソンの方法で行う必要があります。以下は、2つの方法の例です(注釈付きと除外あり):https://manosnikolaidis.wordpress.com/2015/08/25/jackson-without-annotations/

注釈を使用することをお勧めします。しかし、あなたは注釈なしでそれをしたい場合は、ここでのコードだ:

ObjectMapper mapper = new ObjectMapper(); 

    // Avoid having to annotate the Person class 
    // Requires Java 8, pass -parameters to javac 
    // and jackson-module-parameter-names as a dependency 
    mapper.registerModule(new ParameterNamesModule()); 

    // make private fields of Person visible to Jackson 
    mapper.setVisibility(FIELD, ANY); 

あなたはPojoRepositoryでこれを行うにしたい場合は、ObjectMapperを取得し、その上registerModuleとsetVisibilityを呼び出すためにサポートされていないgetObjectMapperメソッドを使用する必要があります:

ObjectMapper objectMapper = ((PojoRepositoryImpl) myClassRepo).getObjectMapper();