-
-
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
7e4e115
commit c8de5aa
Showing
11 changed files
with
148 additions
and
23 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
74 changes: 74 additions & 0 deletions
74
src/test/java/com/fasterxml/jackson/databind/views/ViewsWithSchemaTest.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,74 @@ | ||
package com.fasterxml.jackson.databind.views; | ||
|
||
import java.util.*; | ||
|
||
import com.fasterxml.jackson.annotation.*; | ||
import com.fasterxml.jackson.databind.*; | ||
import com.fasterxml.jackson.databind.jsonFormatVisitors.*; | ||
|
||
public class ViewsWithSchemaTest extends BaseMapTest | ||
{ | ||
interface ViewBC { } | ||
interface ViewAB { } | ||
|
||
@JsonPropertyOrder({ "a", "b", "c" }) | ||
static class POJO { | ||
@JsonView({ ViewAB.class }) | ||
public int a; | ||
|
||
@JsonView({ ViewAB.class, ViewBC.class }) | ||
public int b; | ||
|
||
@JsonView({ ViewBC.class }) | ||
public int c; | ||
} | ||
|
||
static class ListingVisitor extends JsonFormatVisitorWrapper.Base | ||
{ | ||
public final List<String> names = new ArrayList<String>(); | ||
|
||
@Override | ||
public JsonObjectFormatVisitor expectObjectFormat(JavaType type) { | ||
return new JsonObjectFormatVisitor.Base() { | ||
@Override | ||
public void optionalProperty(BeanProperty writer) { | ||
names.add(writer.getName()); | ||
} | ||
|
||
@Override | ||
public void optionalProperty(String name, | ||
JsonFormatVisitable handler, JavaType propertyTypeHint) { | ||
names.add(name); | ||
} | ||
}; | ||
} | ||
} | ||
|
||
/* | ||
/********************************************************** | ||
/* Test methods | ||
/********************************************************** | ||
*/ | ||
|
||
private final ObjectMapper MAPPER = new ObjectMapper(); | ||
|
||
public void testSchemaWithViews() throws Exception | ||
{ | ||
ListingVisitor v = new ListingVisitor(); | ||
MAPPER.writerWithView(ViewBC.class) | ||
.acceptJsonFormatVisitor(POJO.class, v); | ||
assertEquals(Arrays.asList("b", "c"), v.names); | ||
|
||
v = new ListingVisitor(); | ||
MAPPER.writerWithView(ViewAB.class) | ||
.acceptJsonFormatVisitor(POJO.class, v); | ||
assertEquals(Arrays.asList("a", "b"), v.names); | ||
} | ||
|
||
public void testSchemaWithoutViews() throws Exception | ||
{ | ||
ListingVisitor v = new ListingVisitor(); | ||
MAPPER.acceptJsonFormatVisitor(POJO.class, v); | ||
assertEquals(Arrays.asList("a", "b", "c"), v.names); | ||
} | ||
} |