use of javax.json.JsonMergePatch in project jackson-datatype-jsr353 by FasterXML.
the class JsonMergePatchDeserializationTest method testDeserializationAndPatching.
public void testDeserializationAndPatching() throws Exception {
final String json = "{" + "\"name\":\"Json\"" + "}";
final JsonMergePatch jsonMergePatch = MAPPER.readValue(json, JsonMergePatch.class);
final JsonValue jsonPatchAsJsonValue = jsonMergePatch.toJsonValue();
assertThat(jsonPatchAsJsonValue, instanceOf(JsonObject.class));
final JsonObject jsonPatchAsJsonObject = jsonPatchAsJsonValue.asJsonObject();
assertTrue(jsonPatchAsJsonObject.containsKey("name"));
assertThat(jsonPatchAsJsonObject.get("name"), instanceOf(JsonString.class));
assertThat(jsonPatchAsJsonObject.getString("name"), is("Json"));
assertThat(serializeAsString(jsonPatchAsJsonValue), is(json));
final Person person = new Person("John", "Smith");
final JsonValue personJson = MAPPER.convertValue(person, JsonValue.class);
final JsonValue patchedPersonJson = jsonMergePatch.apply(personJson);
final Person patchedPerson = MAPPER.convertValue(patchedPersonJson, Person.class);
assertThat(patchedPerson, is(new Person("Json", "Smith")));
}
Aggregations