gpt4 book ai didi

java - MarkLogic POJO 数据绑定(bind)接口(interface) : JSONMappingException when performing a POJO search

转载 作者:行者123 更新时间:2023-11-30 02:24:53 25 4
gpt4 key购买 nike

我目前正在使用 MarkLogic POJO 数据绑定(bind)接口(interface)。我能够将 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) : JSONMappingException when performing a POJO search,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45904390/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com