-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Only avoid Records fields detection for deserialization. (#3894)
- Loading branch information
Showing
2 changed files
with
56 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
54 changes: 54 additions & 0 deletions
54
...-jdk14/java/com/fasterxml/jackson/databind/records/RecordIgnoreNonAccessorGetterTest.java
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.fasterxml.jackson.databind.records; | ||
|
||
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; | ||
import com.fasterxml.jackson.annotation.JsonPropertyOrder; | ||
import com.fasterxml.jackson.annotation.PropertyAccessor; | ||
import com.fasterxml.jackson.databind.BaseMapTest; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
public class RecordIgnoreNonAccessorGetterTest extends BaseMapTest { | ||
|
||
// [databind#3628] | ||
interface InterfaceWithGetter { | ||
|
||
String getId(); | ||
|
||
String getName(); | ||
} | ||
|
||
@JsonPropertyOrder({"id", "name", "count"}) // easier to assert when JSON field ordering is always the same | ||
record RecordWithInterfaceWithGetter(String name) implements InterfaceWithGetter { | ||
|
||
@Override | ||
public String getId() { | ||
return "ID:" + name; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
// [databind#3895] | ||
public int getCount() { | ||
return 999; | ||
} | ||
} | ||
|
||
private final ObjectMapper MAPPER = newJsonMapper(); | ||
|
||
public void testSerializeIgnoreInterfaceGetter_WithoutUsingVisibilityConfig() throws Exception { | ||
String json = MAPPER.writeValueAsString(new RecordWithInterfaceWithGetter("Bob")); | ||
|
||
assertEquals("{\"id\":\"ID:Bob\",\"name\":\"Bob\",\"count\":999}", json); | ||
} | ||
|
||
public void testSerializeIgnoreInterfaceGetter_UsingVisibilityConfig() throws Exception { | ||
MAPPER.setVisibility(PropertyAccessor.GETTER, Visibility.NONE); | ||
MAPPER.setVisibility(PropertyAccessor.FIELD, Visibility.ANY); | ||
|
||
String json = MAPPER.writeValueAsString(new RecordWithInterfaceWithGetter("Bob")); | ||
|
||
assertEquals("{\"name\":\"Bob\"}", json); | ||
} | ||
} |