目前,我正在使用MarkLogic POJO数据绑定接口。我可以将POJO写入MarkLogic。现在,我想搜索那些POJO并检索搜索结果。我正在按照https://docs.marklogic.com/guide/java/binding#id_89573中的说明进行操作,但是,搜索结果似乎未返回正确的对象。我收到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数据库。此类包含一个成员:private String URI,该成员由"uri/prefix/location2"发起。在上面的示例中,matches.hasContent()返回true。但是,我在PropertyMatches aPM = matches.next();上遇到错误

最佳答案

在MarkLogic中搜索POJO并将其读入Java程序要求POJO具有空的构造函数。在这种情况下,PropertyMatches应该具有public PropertyMatches(){},MatchedPropertyInfo应该具有public MatchedPropertyInfo(){}

关于java - MarkLogic POJO数据绑定(bind)接口(interface):执行POJO搜索时出现JSONMappingException,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45904390/

10-13 07:40