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

Java JsonPatchException类代码示例

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

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



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

示例1: patchUser

import com.github.fge.jsonpatch.JsonPatchException; //导入依赖的package包/类
@PatchMapping("/{id}")
public ResponseEntity patchUser(@PathVariable Long id, @RequestBody JsonPatch jsonPatch) {
  return this.userService
      .getUserByID(id)
      .map(existing -> {
        try {
          JsonNode patched = jsonPatch.apply(objectMapper.convertValue(existing, JsonNode.class));

          UserDTO patchedUser = objectMapper.treeToValue(patched, UserDTO.class);
          // TODO add patched operations
          return ResponseEntity.ok(this.userService.update(patchedUser));
        } catch (JsonPatchException | JsonProcessingException e) {
          return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.getMessage());
        }
      })
      .orElse(ResponseEntity.notFound().build());
}
 
开发者ID:empt-ak,项目名称:meditor,代码行数:18,代码来源:UserRestController.java


示例2: transform

import com.github.fge.jsonpatch.JsonPatchException; //导入依赖的package包/类
@Override
public JsonNode transform(JsonNode patched) throws IOException {
    Iterator<Map.Entry<String, JsonNode>> nodeIterator = patched.get("message").fields();
    while (nodeIterator.hasNext()) {
        Map.Entry<String, JsonNode> entry = nodeIterator.next();

        if (!KNOWN_KEYS.contains(entry.getKey())) {
            String json = format(MOVE_OP, entry.getKey());
            try {
                patched = JsonPatch.fromJson(JacksonUtils.getReader().readTree(json)).apply(patched);
            } catch (JsonPatchException e) {
                throw new RuntimeException("move operation could not be applied", e);
            }
        }
    }

    return patched;
}
 
开发者ID:aerogear,项目名称:aerogear-unifiedpush-server,代码行数:19,代码来源:UserParams.java


示例3: aroundReadFrom

import com.github.fge.jsonpatch.JsonPatchException; //导入依赖的package包/类
@Override
public Object aroundReadFrom(ReaderInterceptorContext context) throws IOException {
    Optional<Object> optionalBean = getCurrentObject();

    if (optionalBean.isPresent()) {
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

        // Currently assume the bean is of type BuiltResponse, this may need to change in the future
        Object bean = ((BuiltResponse) optionalBean.get()).getEntity();

        MessageBodyWriter<? super Object> bodyWriter = providers.getMessageBodyWriter(Object.class, bean.getClass(), new Annotation[0], MediaType.APPLICATION_JSON_TYPE);
        bodyWriter.writeTo(bean, bean.getClass(), bean.getClass(), new Annotation[0], MediaType.APPLICATION_JSON_TYPE, new MultivaluedHashMap<>(), outputStream);

        // Use the Jackson 2.x classes to convert both the incoming patch and the current state of the object into a JsonNode / JsonPatch
        ObjectMapper mapper = new ObjectMapper();
        JsonNode serverState = mapper.readValue(outputStream.toByteArray(), JsonNode.class);
        JsonNode patchAsNode = mapper.readValue(context.getInputStream(), JsonNode.class);
        JsonPatch patch = JsonPatch.fromJson(patchAsNode);

        try {
            JsonNode result = patch.apply(serverState);
            // Stream the result & modify the stream on the readerInterceptor
            ByteArrayOutputStream resultAsByteArray = new ByteArrayOutputStream();
            mapper.writeValue(resultAsByteArray, result);
            context.setInputStream(new ByteArrayInputStream(resultAsByteArray.toByteArray()));

            return context.proceed();

        } catch (JsonPatchException | JsonMappingException e) {
            throw new WebApplicationException(e.getMessage(), e, Response.status(Response.Status.BAD_REQUEST).build());
        }

    } else {
        throw new IllegalArgumentException("No matching GET method on resource");
    }
}
 
开发者ID:projectomakase,项目名称:omakase,代码行数:37,代码来源:JsonPatchInterceptor.java


示例4: onMessage

import com.github.fge.jsonpatch.JsonPatchException; //导入依赖的package包/类
/**
 * SSE incoming message handler
 * @param event type of message
 * @param message message JSON content
 * @throws IOException if JSON syntax is not valid
 */
@Override
public void onMessage(String event, MessageEvent message) throws IOException {
    if ("data".equals(event)) {
        // SSE message is a snapshot
        data = mapper.readTree(message.data);

        // Refresh UI
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                listAdapter.getData().removeAll();
                listAdapter.getData().addAll((ArrayNode) data);
                listAdapter.notifyDataSetChanged();
            }
        });

    } else if ("patch".equals(event)) {
        // SSE message is a patch
        try {
            JsonNode patchNode = mapper.readTree(message.data);
            JsonPatch patch = JsonPatch.fromJson(patchNode);
            data = patch.apply(data);

            // Refresh UI
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    listAdapter.getData().removeAll();
                    listAdapter.getData().addAll((ArrayNode) data);
                    listAdapter.notifyDataSetChanged();
                }
            });
        } catch (JsonPatchException e) {
            e.printStackTrace();
        }
    } else {
        throw new RuntimeException("Unexpected SSE message: " + event);
    }
}
 
开发者ID:streamdataio,项目名称:streamdataio-android,代码行数:46,代码来源:StockMarketList.java


示例5: onMessage

import com.github.fge.jsonpatch.JsonPatchException; //导入依赖的package包/类
/**
 * SSE incoming message handler
 *
 * @param event   type of message
 * @param message message JSON content
 * @throws IOException if JSON syntax is not valid
 */
@Override
public void onMessage(String event, MessageEvent message) throws IOException {

    if ("data".equals(event)) {
        // SSE message is a snapshot
        ownData = mapper.readTree(message.data);

        // Update commits array
        updateCommits();

    } else if ("patch".equals(event)) {
        // SSE message is a patch
        try {
            JsonNode patchNode = mapper.readTree(message.data);
            JsonPatch patch = JsonPatch.fromJson(patchNode);
            ownData = patch.apply(ownData);

            // Get the concerned repository name
            String commitMessage = ownData.get(0).path("commit").path("message").textValue();

            // Spawning an Android notification
            createNotification("New Commit: " + repoName.substring(repoName.indexOf("/") + 1), commitMessage);

            // Update commits array
            updateCommits();
        } catch (JsonPatchException e) {
            e.printStackTrace();
        }
    } else {
        Log.d("Debug", "Disconnecting : " + message.toString());

        if (message.data.contains("HTTP/1.1 401 Unauthorized")) {
            // GitHub api token may be out-of-date --> restart oauth procedure
            SharedPreferences settings = getSharedPreferences("SharedPreferences", Context.MODE_PRIVATE);
            settings.edit().clear().commit();
            startLoginActivity();
        }
        throw new RuntimeException("Wrong SSE message!");
    }
}
 
开发者ID:streamdataio,项目名称:github-android,代码行数:48,代码来源:CommitsActivity.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Java TDoubleProcedure类代码示例发布时间:2022-05-22
下一篇:
Java HotKeyListener类代码示例发布时间: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