This repository has been archived by the owner on Jan 22, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 52
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
44c5057
commit 08f2393
Showing
3 changed files
with
137 additions
and
3 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
130 changes: 130 additions & 0 deletions
130
src/test/java/com/fasterxml/jackson/datatype/guava/OptionalSchema83Test.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,130 @@ | ||
package com.fasterxml.jackson.datatype.guava; | ||
|
||
import java.util.*; | ||
|
||
import com.google.common.base.Optional; | ||
import com.fasterxml.jackson.annotation.*; | ||
import com.fasterxml.jackson.databind.*; | ||
import com.fasterxml.jackson.databind.jsonFormatVisitors.*; | ||
|
||
public class OptionalSchema83Test | ||
extends ModuleTestBase | ||
{ | ||
static class TopLevel { | ||
@JsonProperty("values") | ||
public Optional<CollectionHolder<ValueHolder>> values; | ||
} | ||
|
||
static class ValueHolder { | ||
@JsonProperty("value") | ||
public String value; | ||
} | ||
|
||
static class CollectionHolder<T> { | ||
@JsonProperty("data") | ||
public Collection<T> data; | ||
} | ||
|
||
static class VisitorWrapper implements JsonFormatVisitorWrapper { | ||
private SerializerProvider serializerProvider; | ||
private final String baseName; | ||
private final Set<String> traversedProperties; | ||
|
||
public VisitorWrapper(SerializerProvider serializerProvider, String baseName, Set<String> traversedProperties) { | ||
this.serializerProvider = serializerProvider; | ||
this.baseName = baseName; | ||
this.traversedProperties = traversedProperties; | ||
} | ||
|
||
private VisitorWrapper createSubtraverser(String bn) { | ||
return new VisitorWrapper(getProvider(), bn, traversedProperties); | ||
} | ||
|
||
public Set<String> getTraversedProperties() { | ||
return traversedProperties; | ||
} | ||
|
||
@Override | ||
public JsonObjectFormatVisitor expectObjectFormat(JavaType type) throws JsonMappingException { | ||
return new JsonObjectFormatVisitor.Base(serializerProvider) { | ||
@Override | ||
public void property(BeanProperty prop) throws JsonMappingException { | ||
anyProperty(prop); | ||
} | ||
|
||
@Override | ||
public void optionalProperty(BeanProperty prop) throws JsonMappingException { | ||
anyProperty(prop); | ||
} | ||
|
||
private void anyProperty(BeanProperty prop) throws JsonMappingException { | ||
final String propertyName = prop.getFullName().toString(); | ||
traversedProperties.add(baseName + propertyName); | ||
serializerProvider.findValueSerializer(prop.getType(), prop) | ||
.acceptJsonFormatVisitor(createSubtraverser(baseName + propertyName + "."), prop.getType()); | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public JsonArrayFormatVisitor expectArrayFormat(JavaType type) throws JsonMappingException { | ||
serializerProvider.findValueSerializer(type.getContentType()) | ||
.acceptJsonFormatVisitor(createSubtraverser(baseName), type.getContentType()); | ||
return new JsonArrayFormatVisitor.Base(serializerProvider); | ||
} | ||
|
||
@Override | ||
public JsonStringFormatVisitor expectStringFormat(JavaType type) throws JsonMappingException { | ||
return new JsonStringFormatVisitor.Base(); | ||
} | ||
|
||
@Override | ||
public JsonNumberFormatVisitor expectNumberFormat(JavaType type) throws JsonMappingException { | ||
return new JsonNumberFormatVisitor.Base(); | ||
} | ||
|
||
@Override | ||
public JsonIntegerFormatVisitor expectIntegerFormat(JavaType type) throws JsonMappingException { | ||
return new JsonIntegerFormatVisitor.Base(); | ||
} | ||
|
||
@Override | ||
public JsonBooleanFormatVisitor expectBooleanFormat(JavaType type) throws JsonMappingException { | ||
return new JsonBooleanFormatVisitor.Base(); | ||
} | ||
|
||
@Override | ||
public JsonNullFormatVisitor expectNullFormat(JavaType type) throws JsonMappingException { | ||
return new JsonNullFormatVisitor.Base(); | ||
} | ||
|
||
@Override | ||
public JsonAnyFormatVisitor expectAnyFormat(JavaType type) throws JsonMappingException { | ||
return new JsonAnyFormatVisitor.Base(); | ||
} | ||
|
||
@Override | ||
public JsonMapFormatVisitor expectMapFormat(JavaType type) throws JsonMappingException { | ||
return new JsonMapFormatVisitor.Base(serializerProvider); | ||
} | ||
|
||
@Override | ||
public SerializerProvider getProvider() { | ||
return serializerProvider; | ||
} | ||
|
||
@Override | ||
public void setProvider(SerializerProvider provider) { | ||
this.serializerProvider = provider; | ||
} | ||
} | ||
|
||
public void testOptionalTypeSchema83() throws Exception { | ||
VisitorWrapper wrapper = new VisitorWrapper(null, "", new HashSet<String>()); | ||
mapperWithModule() | ||
.acceptJsonFormatVisitor(TopLevel.class, wrapper); | ||
Set<String> properties = wrapper.getTraversedProperties(); | ||
|
||
assertTrue(properties.contains("values.data.value")); | ||
} | ||
} |