-
-
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.
- Loading branch information
1 parent
7ce734a
commit f97a53f
Showing
13 changed files
with
177 additions
and
74 deletions.
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
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
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
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
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
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
71 changes: 71 additions & 0 deletions
71
src/test/java/com/fasterxml/jackson/databind/views/DefaultViewTest.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,71 @@ | ||
package com.fasterxml.jackson.databind.views; | ||
|
||
import java.io.IOException; | ||
|
||
import com.fasterxml.jackson.annotation.*; | ||
|
||
import com.fasterxml.jackson.databind.*; | ||
|
||
// for [databind#507], supporting default views | ||
public class DefaultViewTest extends BaseMapTest | ||
{ | ||
// Classes that represent views | ||
static class ViewA { } | ||
static class ViewAA extends ViewA { } | ||
static class ViewB { } | ||
static class ViewBB extends ViewB { } | ||
|
||
@JsonView(ViewA.class) | ||
@JsonPropertyOrder({ "a", "b" }) | ||
static class Defaulting { | ||
public int a = 3; | ||
|
||
@JsonView(ViewB.class) | ||
public int b = 5; | ||
} | ||
|
||
/* | ||
/********************************************************** | ||
/* Unit tests | ||
/********************************************************** | ||
*/ | ||
|
||
private final ObjectMapper MAPPER = new ObjectMapper(); | ||
|
||
public void testDeserialization() throws IOException | ||
{ | ||
final String JSON = aposToQuotes("{'a':1,'b':2}"); | ||
|
||
// first: no views: | ||
Defaulting result = MAPPER.readerFor(Defaulting.class) | ||
.readValue(JSON); | ||
assertEquals(result.a, 1); | ||
assertEquals(result.b, 2); | ||
|
||
// Then views; first A, then B(B) | ||
result = MAPPER.readerFor(Defaulting.class) | ||
.withView(ViewA.class) | ||
.readValue(JSON); | ||
assertEquals(result.a, 1); | ||
assertEquals(result.b, 5); | ||
|
||
result = MAPPER.readerFor(Defaulting.class) | ||
.withView(ViewBB.class) | ||
.readValue(JSON); | ||
assertEquals(result.a, 3); | ||
assertEquals(result.b, 2); | ||
} | ||
|
||
public void testSerialization() throws IOException | ||
{ | ||
assertEquals(aposToQuotes("{'a':3,'b':5}"), | ||
MAPPER.writeValueAsString(new Defaulting())); | ||
|
||
assertEquals(aposToQuotes("{'a':3}"), | ||
MAPPER.writerWithView(ViewA.class) | ||
.writeValueAsString(new Defaulting())); | ||
assertEquals(aposToQuotes("{'b':5}"), | ||
MAPPER.writerWithView(ViewB.class) | ||
.writeValueAsString(new Defaulting())); | ||
} | ||
} |
Oops, something went wrong.