本文整理汇总了Java中com.github.fge.jsonpatch.JsonPatch类的典型用法代码示例。如果您正苦于以下问题:Java JsonPatch类的具体用法?Java JsonPatch怎么用?Java JsonPatch使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JsonPatch类属于com.github.fge.jsonpatch包,在下文中一共展示了JsonPatch类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: patchUser
import com.github.fge.jsonpatch.JsonPatch; //导入依赖的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: createUpdateTableMessage
import com.github.fge.jsonpatch.JsonPatch; //导入依赖的package包/类
private UpdateTableMessage createUpdateTableMessage(
final String id,
final long timestamp,
final String requestId,
final String name,
final TableDto oldTable,
final TableDto currentTable
) throws IOException {
final JsonPatch patch = JsonDiff.asJsonPatch(
this.mapper.valueToTree(oldTable),
this.mapper.valueToTree(currentTable)
);
return new UpdateTableMessage(
id,
timestamp,
requestId,
name,
new UpdatePayload<>(oldTable, patch)
);
}
开发者ID:Netflix,项目名称:metacat,代码行数:21,代码来源:SNSNotificationServiceImpl.java
示例3: transform
import com.github.fge.jsonpatch.JsonPatch; //导入依赖的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
示例4: UpdatePayload
import com.github.fge.jsonpatch.JsonPatch; //导入依赖的package包/类
/**
* Create a new update payload.
*
* @param previous The previous version of the object that was updated
* @param patch The JSON patch to go from previous to current
*/
@JsonCreator
public UpdatePayload(
@JsonProperty("previous") final T previous,
@JsonProperty("patch") final JsonPatch patch
) {
this.previous = previous;
this.patch = patch;
}
开发者ID:Netflix,项目名称:metacat,代码行数:15,代码来源:UpdatePayload.java
示例5: notAuthorizedPatch
import com.github.fge.jsonpatch.JsonPatch; //导入依赖的package包/类
@Test
public void notAuthorizedPatch() throws IOException {
ObjectMapper mapper = new ObjectMapper();
JsonPatch patch = mapper
.readValue("[{ \"op\": \"remove\", \"path\": \"/password\" }]", JsonPatch.class);
HttpEntity<JsonPatch> patchEntity = new HttpEntity<>(patch);
is401(this.restTemplate
.exchange(getPath("/api/user/{id}"), HttpMethod.PATCH, patchEntity, UserDTO.class, 1L));
}
开发者ID:empt-ak,项目名称:meditor,代码行数:12,代码来源:UserRestControllerTest.java
示例6: aroundReadFrom
import com.github.fge.jsonpatch.JsonPatch; //导入依赖的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
示例7: onMessage
import com.github.fge.jsonpatch.JsonPatch; //导入依赖的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
示例8: onMessage
import com.github.fge.jsonpatch.JsonPatch; //导入依赖的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.JsonPatch类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论