• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java JsonDiff类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.flipkart.zjsonpatch.JsonDiff的典型用法代码示例。如果您正苦于以下问题:Java JsonDiff类的具体用法?Java JsonDiff怎么用?Java JsonDiff使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



JsonDiff类属于com.flipkart.zjsonpatch包,在下文中一共展示了JsonDiff类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testJsonDiff

import com.flipkart.zjsonpatch.JsonDiff; //导入依赖的package包/类
@Test
public void testJsonDiff() throws Exception
{
    String f_base = "src/test/resources/brat_normal.json";
    String f_addedMiddle = "src/test/resources/brat_added_entity_near_middle.json";
    String f_removedMiddle = "src/test/resources/brat_removed_entity_in_middle.json";
    String f_removedEnd = "src/test/resources/brat_removed_entity_near_end.json";

    MappingJackson2HttpMessageConverter jsonConverter = 
            new MappingJackson2HttpMessageConverter();
    
    ObjectMapper mapper = jsonConverter.getObjectMapper();
    
    JsonNode base = mapper.readTree(new File(f_base));
    JsonNode addedMiddle = mapper.readTree(new File(f_addedMiddle));
    JsonNode removedMiddle = mapper.readTree(new File(f_removedMiddle));
    JsonNode removedEnd = mapper.readTree(new File(f_removedEnd));
    
    JsonNode d_addedMiddle = JsonDiff.asJson(base, addedMiddle);
    JsonNode d_removedMiddle = JsonDiff.asJson(base, removedMiddle);
    JsonNode d_removedEnd = JsonDiff.asJson(base, removedEnd);
    
    System.out.println(d_addedMiddle);
    System.out.println(d_removedMiddle);
    System.out.println(d_removedEnd);
}
 
开发者ID:webanno,项目名称:webanno,代码行数:27,代码来源:CasToBratJsonTest.java


示例2: matches

import com.flipkart.zjsonpatch.JsonDiff; //导入依赖的package包/类
/**
 * Evaluates the matcher for argument <var>actualJson</var>.
 *
 * @param actualJson the JSON content against which the matcher is evaluated.
 * @return <code>true</code> if <var>actualJson</var> matches <var>expectedJson</var>, otherwise <code>false</code>.
 */
@Override
public boolean matches(Object actualJson) {
    try {
        JsonNode actual = objectMapper.readTree(actualJson.toString());
        JsonNode expected = objectMapper.readTree(expectedJson);
        String diff = JsonDiff.asJson(actual, expected).toString();
        return diff.equals("[]");
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:YashchenkoN,项目名称:jsonverifier,代码行数:18,代码来源:JsonMatcher.java


示例3: assertJson

import com.flipkart.zjsonpatch.JsonDiff; //导入依赖的package包/类
/**
 * compare JSON to the content of the specified file
 *
 * @param actualJson        JSON to compare
 * @param expectedFileName  file name from which to load expected content
 * @throws IOException          if an I/O error occurs
 * @throws NullPointerException if the file doesn't exist
 */
public void assertJson(String actualJson, String expectedFileName) throws IOException {
    String path = String.format(PATH, testClass.getSimpleName(), methodName, expectedFileName);
    try (InputStream resourceAsStream = testClass.getClassLoader().getResourceAsStream(path)) {
        String expectedJson = IOUtils.toString(resourceAsStream, Charset.defaultCharset());
        JsonNode actual = objectMapper.readTree(actualJson);
        JsonNode expected = objectMapper.readTree(expectedJson);

        LOGGER.info("EXPECTED JSON: " + expectedJson);
        LOGGER.info("ACTUAL JSON: " + actualJson);

        String diff = JsonDiff.asJson(actual, expected).toString();
        if (!diff.equals("[]")) {
            throw new AssertionFailedError("Json objects are not equal: " + diff);
        }
    }
}
 
开发者ID:YashchenkoN,项目名称:jsonverifier,代码行数:25,代码来源:JsonContentVerifier.java


示例4: computeJsonPatch

import com.flipkart.zjsonpatch.JsonDiff; //导入依赖的package包/类
private JsonNode computeJsonPatch(Response response) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    JsonFactory factory = mapper.getFactory();
    JsonNode actualJsonTree = factory.createParser(response.getBody()).readValueAsTree();
    JsonNode expectedJsonTree = factory.createParser(expectedJson).readValueAsTree();
    JsonNode jsonPatch = JsonDiff.asJson(actualJsonTree, expectedJsonTree);
    removeReplaceOpsForIgnoredFields(jsonPatch);
    removeMoveOpsForOrderIgnoredFields(jsonPatch);
    return jsonPatch;
}
 
开发者ID:bastion-dev,项目名称:Bastion,代码行数:11,代码来源:JsonResponseAssertions.java


示例5: execute

import com.flipkart.zjsonpatch.JsonDiff; //导入依赖的package包/类
private void execute(String path) throws Exception {
  String raw = GeneralUtils.loadResource(AstEmitterTest.class, path);
  Map<String, String> sections = TestCaseParser.parseSections(raw);
  String source = sections.get("SOURCE").trim();
  CompiledTemplate template = compiler().compile(source);

  String json = sections.get("JSON").trim();
  JsonNode expected = JsonUtils.decode(json);

  JsonNode actual = AstEmitter.get(template.code());

  // TODO: improve the diff formatting.
  String diff = JsonDiff.asJson(expected, actual).toString();
  assertEquals(actual.toString(), expected.toString(), diff);
}
 
开发者ID:Squarespace,项目名称:template-compiler,代码行数:16,代码来源:AstEmitterTest.java


示例6: computeNext

import com.flipkart.zjsonpatch.JsonDiff; //导入依赖的package包/类
public Changeset computeNext(JsonNode document) throws IOException {
    final String documentId = document.get("id").asText();
    final Optional<JsonNode> persistentDocument = getDocument(documentId);
    final JsonNode patch = JsonDiff.asJson(persistentDocument.orElse(mapper.createObjectNode()), document);
    return new Changeset(documentId, retrieveLastOrderNumber(documentId) + 1L, filterExcludedFields(patch));
}
 
开发者ID:pivio,项目名称:pivio-server,代码行数:7,代码来源:ChangesetService.java


示例7: bratRenderCommand

import com.flipkart.zjsonpatch.JsonDiff; //导入依赖的package包/类
private String bratRenderCommand(JCas aJCas)
    {
        StopWatch timer = new StopWatch();
        timer.start();
        
        GetDocumentResponse response = new GetDocumentResponse();
        render(response, aJCas);
        String json = toJson(response);
        
        // By default, we do a full rendering...
        RenderType renderType = RenderType.FULL;
        String cmd = "renderData";
        String data = json;

        // ... try to render diff
        String diff = null;
        JsonNode current = null;
        JsonNode previous = null;
        try {
            ObjectMapper mapper = JSONUtil.getJsonConverter().getObjectMapper();
            current = mapper.readTree(json);
            previous = lastRenderedJson != null ? mapper.readTree(lastRenderedJson) : null;
        }
        catch (IOException e) {
            LOG.error("Unable to generate diff, falling back to full render.", e);
            // Fall-through
        }
        
        if (previous != null && current != null) {
            diff = JsonDiff.asJson(previous, current).toString();
 
            // Only sent a patch if it is smaller than sending the full data. E.g. when switching
            // pages, the patch usually ends up being twice as large as the full data.
            if (diff.length() < json.length()) {
                cmd = "renderDataPatch";
                data = diff;
                renderType = RenderType.DIFFERENTIAL;
            }
            
//            LOG.info("Diff:  " + diff);
//            LOG.info("Full: {}   Patch: {}   Diff time: {}", json.length(), diff.length(), timer);
        }
        
        // Storing the last rendered JSON as string because JsonNodes are not serializable.
        lastRenderedJson = json;
        
        timer.stop();

        metrics.renderComplete(renderType, timer.getTime(), json, diff);
        
        return "Wicket.$('" + vis.getMarkupId() + "').dispatcher.post('" + cmd + "', [" + data
                + "]);";
    }
 
开发者ID:webanno,项目名称:webanno,代码行数:54,代码来源:BratAnnotationEditor.java



注:本文中的com.flipkart.zjsonpatch.JsonDiff类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java PaodingAnalyzer类代码示例发布时间:2022-05-22
下一篇:
Java RangeIteratorBase类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap