-
Notifications
You must be signed in to change notification settings - Fork 562
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DATAREST-1524 - Fix deserialization of transient fiels with setters.
Patching of non persistent field was broken after DATAREST-1383. And now it is again inline with PUT.
- Loading branch information
1 parent
060c84d
commit 1d1370f
Showing
2 changed files
with
39 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,6 +74,7 @@ | |
* @author Mathias Düsterhöft | ||
* @author Ken Dombeck | ||
* @author Thomas Mrozinski | ||
* @author Bas Schoenmaeckers | ||
*/ | ||
@RunWith(MockitoJUnitRunner.class) | ||
public class DomainObjectReaderUnitTests { | ||
|
@@ -576,6 +577,22 @@ public void doesNotWipeReadOnlyPropertyForPatch() throws Exception { | |
assertThat(result.email).isEqualTo("[email protected]"); | ||
} | ||
|
||
@Test // DATAREST-1524 | ||
public void useTransientSettersWithNonPersistentPropertiesForPatch() throws Exception { | ||
SampleUser user = new SampleUser("name", "password"); | ||
user.lastLogin = new Date(); | ||
user.email = "[email protected]"; | ||
user.nonPersistentField = false; | ||
|
||
ObjectMapper mapper = new ObjectMapper(); | ||
ObjectNode source = (ObjectNode) mapper.readTree("{ \"online\" : true}"); | ||
|
||
@SuppressWarnings("deprecation") | ||
SampleUser result = reader.merge(source, user, mapper); | ||
|
||
assertThat(result.isOnline()).isTrue(); | ||
} | ||
|
||
@Test // DATAREST-1068 | ||
public void arraysCanBeResizedDuringMerge() throws Exception { | ||
ObjectMapper mapper = new ObjectMapper(); | ||
|
@@ -606,6 +623,22 @@ static class SampleUser { | |
@ReadOnlyProperty // | ||
private String email; | ||
|
||
@Transient | ||
@JsonIgnore | ||
boolean nonPersistentField; | ||
|
||
@Transient | ||
@JsonProperty | ||
public boolean isOnline() { | ||
return nonPersistentField; | ||
} | ||
|
||
@Transient | ||
@JsonProperty | ||
public void setOnline(Boolean online) { | ||
this.nonPersistentField = online; | ||
} | ||
|
||
public SampleUser(String name, String password) { | ||
|
||
this.name = name; | ||
|