下面列出了怎么用com.fasterxml.jackson.databind.jsonFormatVisitors.JsonObjectFormatVisitor的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public void depositSchemaProperty(final JsonObjectFormatVisitor visitor,
SerializerProvider provider) throws JsonMappingException
{
JsonSerializer<Object> ser = provider
.findValueSerializer(this.getType(), this)
.unwrappingSerializer(_nameTransformer);
if (ser.isUnwrappingSerializer()) {
ser.acceptJsonFormatVisitor(new JsonFormatVisitorWrapper.Base(provider) {
// an unwrapping serializer will always expect ObjectFormat,
// hence, the other cases do not have to be implemented
@Override
public JsonObjectFormatVisitor expectObjectFormat(JavaType type)
throws JsonMappingException {
return visitor;
}
}, this.getType());
} else {
super.depositSchemaProperty(visitor, provider);
}
}
@Override
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint)
throws JsonMappingException
{
if (visitor != null) {
JsonObjectFormatVisitor objectVisitor = visitor.expectObjectFormat(typeHint);
if (objectVisitor != null) {
if (_endpointSerializer != null) {
JavaType endpointType = _rangeType.containedType(0);
JavaType btType = visitor.getProvider().constructType(BoundType.class);
// should probably keep track of `property`...
JsonSerializer<?> btSer = visitor.getProvider()
.findContentValueSerializer(btType, null);
objectVisitor.property(_fieldNames.lowerEndpoint, _endpointSerializer, endpointType);
objectVisitor.property(_fieldNames.lowerBoundType, btSer, btType);
objectVisitor.property(_fieldNames.upperEndpoint, _endpointSerializer, endpointType);
objectVisitor.property(_fieldNames.upperBoundType, btSer, btType);
}
}
}
}
@Override
public void acceptJsonFormatVisitor(final JsonFormatVisitorWrapper wrapper, final JavaType hint)
throws JsonMappingException {
@Nullable final JsonObjectFormatVisitor visitor = wrapper.expectObjectFormat(hint);
if (visitor == null) {
return;
}
final SerializerProvider provider = wrapper.getProvider();
visitor.property(names.getAmount(),
provider.findValueSerializer(writer.getType()),
provider.constructType(writer.getType()));
visitor.property(names.getCurrency(),
provider.findValueSerializer(CurrencyUnit.class),
provider.constructType(CurrencyUnit.class));
visitor.optionalProperty(names.getFormatted(),
provider.findValueSerializer(String.class),
provider.constructType(String.class));
}
@Override
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint)
throws JsonMappingException
{
//deposit your output format
if (visitor == null) {
return;
}
JsonObjectFormatVisitor objectVisitor = visitor.expectObjectFormat(typeHint);
if (objectVisitor == null) {
return;
}
final SerializerProvider provider = visitor.getProvider();
if (_propertyFilterId != null) {
PropertyFilter filter = findPropertyFilter(visitor.getProvider(),
_propertyFilterId, null);
for (int i = 0, end = _props.length; i < end; ++i) {
filter.depositSchemaProperty(_props[i], objectVisitor, provider);
}
} else {
Class<?> view = ((_filteredProps == null) || (provider == null))
? null : provider.getActiveView();
final BeanPropertyWriter[] props;
if (view != null) {
props = _filteredProps;
} else {
props = _props;
}
for (int i = 0, end = props.length; i < end; ++i) {
BeanPropertyWriter prop = props[i];
if (prop != null) { // may be filtered out unconditionally
prop.depositSchemaProperty(objectVisitor, provider);
}
}
}
}
@Override
public void depositSchemaProperty(JsonObjectFormatVisitor objectVisitor,
SerializerProvider provider)
throws JsonMappingException
{
_property.depositSchemaProperty(objectVisitor, provider);
}
@Override
public void depositSchemaProperty(JsonObjectFormatVisitor v,
SerializerProvider provider) throws JsonMappingException {
if (v != null) {
if (isRequired()) {
v.property(this);
} else {
v.optionalProperty(this);
}
}
}
@Deprecated
@Override
public void depositSchemaProperty(BeanPropertyWriter writer,
JsonObjectFormatVisitor objectVisitor, SerializerProvider provider)
throws JsonMappingException
{
if (include(writer)) {
writer.depositSchemaProperty(objectVisitor, provider);
}
}
@Override
public void depositSchemaProperty(PropertyWriter writer,
JsonObjectFormatVisitor objectVisitor,
SerializerProvider provider) throws JsonMappingException
{
if (include(writer)) {
writer.depositSchemaProperty(objectVisitor, provider);
}
}
@Override
public void depositSchemaProperty(JsonObjectFormatVisitor v,
SerializerProvider provider) throws JsonMappingException
{
Class<?> activeView = provider.getActiveView();
if (activeView == null || _view.isAssignableFrom(activeView)) {
super.depositSchemaProperty(v, provider);
}
}
@Override
public void depositSchemaProperty(JsonObjectFormatVisitor v,
SerializerProvider provider) throws JsonMappingException
{
if (_inView(provider.getActiveView())) {
super.depositSchemaProperty(v, provider);
}
}
@Override
public void depositSchemaProperty(JsonObjectFormatVisitor objectVisitor,
SerializerProvider provider)
throws JsonMappingException
{
if (isRequired()) {
objectVisitor.property(this);
} else {
objectVisitor.optionalProperty(this);
}
}
@Override
public JsonObjectFormatVisitor expectObjectFormat(JavaType type) {
// from ProtoBufSchemaVisitor
MessageElementVisitor visitor = new CustomMessageElementVisitor(_provider, type, _definedTypeElementBuilders, _isNested, customizedDataTypes);
_builder = visitor;
_definedTypeElementBuilders.addTypeElement(type, visitor, _isNested);
return visitor;
}
@Override
public JsonObjectFormatVisitor expectObjectFormat(JavaType type) {
// from ProtobufSchemaGenerator
_rootType = type;
MessageElementVisitor visitor = new CustomMessageElementVisitor(_provider, type, _definedTypeElementBuilders, _isNested, customizedDataTypes);
_builder = visitor;
_definedTypeElementBuilders.addTypeElement(type, visitor, _isNested);
return visitor;
}
@Override
public JsonObjectFormatVisitor expectObjectFormat(JavaType type) throws JsonMappingException {
addFieldIfPresent("Object");
if (shouldExpand() && (topLevelPath() || !wasVisited(type))) {
log.trace("({}) {} expanding", path, toString(type));
return new FieldDocumentationObjectVisitor(provider, context, path,
withVisitedType(type), typeFactory, skipAccessor);
} else {
log.trace("({}) {} NOT expanding", path, toString(type));
return new JsonObjectFormatVisitor.Base();
}
}
@Override
public void depositSchemaProperty(final PropertyWriter writer,
final JsonObjectFormatVisitor objectVisitor,
final SerializerProvider provider) throws JsonMappingException {
if (include(writer.getName())) {
writer.depositSchemaProperty(objectVisitor, provider);
}
}
@Override
public void depositSchemaProperty(JsonObjectFormatVisitor objectVisitor,
SerializerProvider provider) throws JsonMappingException {
}
/**
* Traversal method used for things like JSON Schema generation, or
* POJO introspection.
*/
@Override
public abstract void depositSchemaProperty(JsonObjectFormatVisitor objectVisitor,
SerializerProvider provider)
throws JsonMappingException;
@Override
public void depositSchemaProperty(PropertyWriter writer, JsonObjectFormatVisitor objectVisitor, SerializerProvider provider) throws JsonMappingException {
writer.depositSchemaProperty(objectVisitor, provider);
}
/**
* Method that can be called to visit the type structure that this
* property is part of.
* Note that not all implementations support traversal with this
* method; those that do not should throw
* {@link UnsupportedOperationException}.
*<p>
* NOTE: Starting with 2.7, takes explicit {@link SerializerProvider}
* argument to reduce the need to rely on provider visitor may or may not
* have assigned.
*
* @param objectVisitor Visitor to used as the callback handler
*
* @since 2.2 (although signature did change in 2.7)
*/
public void depositSchemaProperty(JsonObjectFormatVisitor objectVisitor,
SerializerProvider provider)
throws JsonMappingException;
/**
* Implementation of this method throws
* {@link UnsupportedOperationException}, since instances of this
* implementation should not be used as part of actual structure
* visited. Rather, other implementations should handle it.
*/
@Override
public void depositSchemaProperty(JsonObjectFormatVisitor objectVisitor,
SerializerProvider provider) {
throw new UnsupportedOperationException("Instances of "+getClass().getName()+" should not get visited");
}
/**
* Method called by {@link BeanSerializer} to let the filter determine whether, and in what
* form the given property exist within the parent, or root, schema. Filters can omit
* adding the property to the node, or choose the form of the schema value for the property
*<p>
* Typical implementation is something like:
*<pre>
* if (include(writer)) {
* writer.depositSchemaProperty(objectVisitor, provider);
* }
*</pre>
*
* @param writer Bean property serializer to use to create schema value
* @param objectVisitor JsonObjectFormatVisitor which should be aware of
* the property's existence
* @param provider Provider that can be used for accessing dynamic aspects of serialization
* processing
*
* @since 2.1
*/
public void depositSchemaProperty(BeanPropertyWriter writer, JsonObjectFormatVisitor objectVisitor,
SerializerProvider provider)
throws JsonMappingException;
/**
* Method called by {@link BeanSerializer} to let the filter determine whether, and in what
* form the given property exist within the parent, or root, schema. Filters can omit
* adding the property to the node, or choose the form of the schema value for the property
*<p>
* Typical implementation is something like:
*<pre>
* if (include(writer)) {
* writer.depositSchemaProperty(objectVisitor, provider);
* }
*</pre>
*
* @param writer Bean property serializer to use to create schema value
* @param objectVisitor JsonObjectFormatVisitor which should be aware of
* the property's existence
* @param provider Provider that can be used for accessing dynamic aspects of serialization
* processing
*/
public void depositSchemaProperty(PropertyWriter writer, JsonObjectFormatVisitor objectVisitor,
SerializerProvider provider)
throws JsonMappingException;