Java Code Examples for com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper#getProvider()

The following examples show how to use com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper#getProvider() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MultimapSerializer.java    From jackson-datatypes-collections with Apache License 2.0 6 votes vote down vote up
@Override
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint)
    throws JsonMappingException
{
    JsonMapFormatVisitor v2 = (visitor == null) ? null : visitor.expectMapFormat(typeHint);        
    if (v2 != null) {
        v2.keyFormat(_keySerializer, _type.getKeyType());
        JsonSerializer<?> valueSer = _valueSerializer;
        final JavaType vt = _type.getContentType();
        final SerializerProvider prov = visitor.getProvider();
        if (valueSer == null) {
            valueSer = _findAndAddDynamic(prov, vt);
        }
        final JsonSerializer<?> valueSer2 = valueSer;
        v2.valueFormat(new JsonFormatVisitable() {
            final JavaType arrayType = prov.getTypeFactory().constructArrayType(vt);
            @Override
            public void acceptJsonFormatVisitor(
                    JsonFormatVisitorWrapper v3, JavaType hint3)
                throws JsonMappingException
            {
                JsonArrayFormatVisitor v4 = v3.expectArrayFormat(arrayType);
                if (v4 != null) {
                    v4.itemsFormat(valueSer2, vt);
                }
            }
        }, vt);
    }
}
 
Example 2
Source File: MonetaryAmountSerializer.java    From jackson-datatype-money with MIT License 6 votes vote down vote up
@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));
}
 
Example 3
Source File: EnumSerializer.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint)
    throws JsonMappingException
{
    SerializerProvider serializers = visitor.getProvider();
    if (_serializeAsIndex(serializers)) {
        visitIntFormat(visitor, typeHint, JsonParser.NumberType.INT);
        return;
    }
    JsonStringFormatVisitor stringVisitor = visitor.expectStringFormat(typeHint);
    if (stringVisitor != null) {
        Set<String> enums = new LinkedHashSet<String>();
        
        // Use toString()?
        if ((serializers != null) && 
                serializers.isEnabled(SerializationFeature.WRITE_ENUMS_USING_TO_STRING)) {
            for (Enum<?> e : _values.enums()) {
                enums.add(e.toString());
            }
        } else {
            // No, serialize using name() or explicit overrides
            for (SerializableString value : _values.values()) {
                enums.add(value.getValue());
            }
        }
        stringVisitor.enumTypes(enums);
    }
}
 
Example 4
Source File: BeanSerializerBase.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@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);
            }
        }
    }
}
 
Example 5
Source File: YearMonthSerializer.java    From jackson-modules-java8 with Apache License 2.0 5 votes vote down vote up
@Override
protected void _acceptTimestampVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) throws JsonMappingException
{
    SerializerProvider provider = visitor.getProvider();
    boolean useTimestamp = (provider != null) && useTimestamp(provider);
    if (useTimestamp) {
        super._acceptTimestampVisitor(visitor, typeHint);
    } else {
        JsonStringFormatVisitor v2 = visitor.expectStringFormat(typeHint);
        if (v2 != null) {
            v2.format(JsonValueFormat.DATE_TIME);
        }
    }
}
 
Example 6
Source File: DurationSerializer.java    From jackson-modules-java8 with Apache License 2.0 5 votes vote down vote up
@Override
protected void _acceptTimestampVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) throws JsonMappingException
{
    JsonIntegerFormatVisitor v2 = visitor.expectIntegerFormat(typeHint);
    if (v2 != null) {
        v2.numberType(JsonParser.NumberType.LONG);
        SerializerProvider provider = visitor.getProvider();
        if ((provider != null) && useNanoseconds(provider)) {
            // big number, no more specific qualifier to use...
        } else { // otherwise good old Unix timestamp, in milliseconds
            v2.format(JsonValueFormat.UTC_MILLISEC);
        }
    }
}
 
Example 7
Source File: LocalDateSerializer.java    From jackson-modules-java8 with Apache License 2.0 5 votes vote down vote up
@Override
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) throws JsonMappingException
{
    SerializerProvider provider = visitor.getProvider();
    boolean useTimestamp = (provider != null) && useTimestamp(provider);
    if (useTimestamp) {
        _acceptTimestampVisitor(visitor, typeHint);
    } else {
        JsonStringFormatVisitor v2 = visitor.expectStringFormat(typeHint);
        if (v2 != null) {
            v2.format(JsonValueFormat.DATE);
        }
    }
}