com.fasterxml.jackson.core.type.WritableTypeId Java Examples

The following examples show how to use com.fasterxml.jackson.core.type.WritableTypeId. 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: AwsModule.java    From beam with Apache License 2.0 6 votes vote down vote up
@Override
public void serializeWithType(
    AwsCredentialsProvider credentialsProvider,
    JsonGenerator jsonGenerator,
    SerializerProvider serializer,
    TypeSerializer typeSerializer)
    throws IOException {
  WritableTypeId typeId =
      typeSerializer.writeTypePrefix(
          jsonGenerator, typeSerializer.typeId(credentialsProvider, JsonToken.START_OBJECT));
  if (credentialsProvider.getClass().equals(StaticCredentialsProvider.class)) {
    jsonGenerator.writeStringField(
        ACCESS_KEY_ID, credentialsProvider.resolveCredentials().accessKeyId());
    jsonGenerator.writeStringField(
        SECRET_ACCESS_KEY, credentialsProvider.resolveCredentials().secretAccessKey());
  } else if (!SINGLETON_CREDENTIAL_PROVIDERS.contains(credentialsProvider.getClass())) {
    throw new IllegalArgumentException(
        "Unsupported AWS credentials provider type " + credentialsProvider.getClass());
  }
  typeSerializer.writeTypeSuffix(jsonGenerator, typeId);
}
 
Example #2
Source File: ObjectNode.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void serializeWithType(JsonGenerator g, SerializerProvider provider,
        TypeSerializer typeSer)
    throws IOException
{
    @SuppressWarnings("deprecation")
    boolean trimEmptyArray = (provider != null) &&
            !provider.isEnabled(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS);

    WritableTypeId typeIdDef = typeSer.writeTypePrefix(g,
            typeSer.typeId(this, JsonToken.START_OBJECT));
    for (Map.Entry<String, JsonNode> en : _children.entrySet()) {
        BaseJsonNode value = (BaseJsonNode) en.getValue();

        // check if WRITE_EMPTY_JSON_ARRAYS feature is disabled,
        // if the feature is disabled, then should not write an empty array
        // to the output, so continue to the next element in the iteration
        if (trimEmptyArray && value.isArray() && value.isEmpty(provider)) {
            continue;
        }
        
        g.writeFieldName(en.getKey());
        value.serialize(g, provider);
    }
    typeSer.writeTypeSuffix(g, typeIdDef);
}
 
Example #3
Source File: BeanAsArraySerializer.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void serializeWithType(Object bean, JsonGenerator gen,
        SerializerProvider provider, TypeSerializer typeSer)
    throws IOException
{
    /* 10-Dec-2014, tatu: Not sure if this can be made to work reliably;
     *   but for sure delegating to default implementation will not work. So:
     */
    if (_objectIdWriter != null) {
        _serializeWithObjectId(bean, gen, provider, typeSer);
        return;
    }
    gen.setCurrentValue(bean);
    WritableTypeId typeIdDef = _typeIdDef(typeSer, bean, JsonToken.START_ARRAY);
    typeSer.writeTypePrefix(gen, typeIdDef);
    serializeAsArray(bean, gen, provider);
    typeSer.writeTypeSuffix(gen, typeIdDef);
}
 
Example #4
Source File: StdArraySerializers.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void serializeWithType(char[] value, JsonGenerator g, SerializerProvider provider,
        TypeSerializer typeSer)
    throws IOException
{
    // [JACKSON-289] allows serializing as 'sparse' char array too:
    final boolean asArray = provider.isEnabled(SerializationFeature.WRITE_CHAR_ARRAYS_AS_JSON_ARRAYS);
    WritableTypeId typeIdDef;
    if (asArray) {
        typeIdDef = typeSer.writeTypePrefix(g,
                typeSer.typeId(value, JsonToken.START_ARRAY));
        _writeArrayContents(g, value);
    } else { // default is to write as simple String
        typeIdDef = typeSer.writeTypePrefix(g,
                typeSer.typeId(value, JsonToken.VALUE_STRING));
        g.writeString(value, 0, value.length);
    }
    typeSer.writeTypeSuffix(g, typeIdDef);
}
 
Example #5
Source File: ByteArraySerializer.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void serializeWithType(byte[] value, JsonGenerator g, SerializerProvider provider,
        TypeSerializer typeSer)
    throws IOException
{
    // most likely scalar
    WritableTypeId typeIdDef = typeSer.writeTypePrefix(g,
            typeSer.typeId(value, JsonToken.VALUE_EMBEDDED_OBJECT));
    g.writeBinary(provider.getConfig().getBase64Variant(),
            value, 0, value.length);
    typeSer.writeTypeSuffix(g, typeIdDef);

    /* OLD impl
    typeSer.writeTypePrefixForScalar(value, g);
    g.writeBinary(provider.getConfig().getBase64Variant(),
            value, 0, value.length);
    typeSer.writeTypeSuffixForScalar(value, g);
    */
}
 
Example #6
Source File: BeanSerializerBase.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
protected  void _serializeObjectId(Object bean, JsonGenerator g,
        SerializerProvider provider,
        TypeSerializer typeSer, WritableObjectId objectId) throws IOException
{
    final ObjectIdWriter w = _objectIdWriter;
    WritableTypeId typeIdDef = _typeIdDef(typeSer, bean, JsonToken.START_OBJECT);

    typeSer.writeTypePrefix(g, typeIdDef);
    objectId.writeAsField(g, provider, w);
    if (_propertyFilterId != null) {
        serializeFieldsFiltered(bean, g, provider);
    } else {
        serializeFields(bean, g, provider);
    }
    typeSer.writeTypeSuffix(g, typeIdDef);
}
 
Example #7
Source File: BeanSerializerBase.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void serializeWithType(Object bean, JsonGenerator gen,
        SerializerProvider provider, TypeSerializer typeSer)
    throws IOException
{
    if (_objectIdWriter != null) {
        gen.setCurrentValue(bean); // [databind#631]
        _serializeWithObjectId(bean, gen, provider, typeSer);
        return;
    }

    gen.setCurrentValue(bean); // [databind#631]
    WritableTypeId typeIdDef = _typeIdDef(typeSer, bean, JsonToken.START_OBJECT);
    typeSer.writeTypePrefix(gen, typeIdDef);
    if (_propertyFilterId != null) {
        serializeFieldsFiltered(bean, gen, provider);
    } else {
        serializeFields(bean, gen, provider);
    }
    typeSer.writeTypeSuffix(gen, typeIdDef);
}
 
Example #8
Source File: MultimapSerializer.java    From jackson-datatypes-collections with Apache License 2.0 6 votes vote down vote up
@Override
    public void serializeWithType(Multimap<?,?> value, JsonGenerator gen,
            SerializerProvider ctxt, TypeSerializer typeSer)
        throws IOException
    {
        gen.setCurrentValue(value);
        WritableTypeId typeIdDef = typeSer.writeTypePrefix(gen, ctxt,
                typeSer.typeId(value, JsonToken.START_OBJECT));
        if (!value.isEmpty()) {
// 20-Mar-2017, tatu: And this is where [datatypes-collections#7] would be
//     plugged in...
//            if (_sortKeys || provider.isEnabled(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS)) {
//              value = _orderEntries(value, gen, provider);
//          }
            if (_filterId != null) {
                serializeFilteredFields(value, gen, ctxt);
            } else {
                serializeFields(value, gen, ctxt);
            }
        }
        typeSer.writeTypeSuffix(gen, ctxt, typeIdDef);
    }
 
Example #9
Source File: MapSerializer.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void serializeWithType(Map<?,?> value, JsonGenerator gen, SerializerProvider provider,
        TypeSerializer typeSer)
    throws IOException
{
    // [databind#631]: Assign current value, to be accessible by custom serializers
    gen.setCurrentValue(value);
    WritableTypeId typeIdDef = typeSer.writeTypePrefix(gen,
            typeSer.typeId(value, JsonToken.START_OBJECT));
    if (!value.isEmpty()) {
        if (_sortKeys || provider.isEnabled(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS)) {
            value = _orderEntries(value, gen, provider);
        }
        PropertyFilter pf;
        if ((_filterId != null) && (pf = findPropertyFilter(provider, _filterId, value)) != null) {
            serializeFilteredFields(value, gen, provider, pf, _suppressableValue);
        } else if ((_suppressableValue != null) || _suppressNulls) {
            serializeOptionalFields(value, gen, provider, _suppressableValue);
        } else if (_valueSerializer != null) {
            serializeFieldsUsing(value, gen, provider, _valueSerializer);
        } else {
            serializeFields(value, gen, provider);
        }
    }
    typeSer.writeTypeSuffix(gen, typeIdDef);
}
 
Example #10
Source File: CharIterableSerializer.java    From jackson-datatypes-collections with Apache License 2.0 6 votes vote down vote up
@Override
public void serializeWithType(
        CharIterable value,
        JsonGenerator g,
        SerializerProvider ctxt,
        TypeSerializer typeSer
) throws IOException {
    g.setCurrentValue(value);
    WritableTypeId typeIdDef;
    if (ctxt.isEnabled(SerializationFeature.WRITE_CHAR_ARRAYS_AS_JSON_ARRAYS)) {
        typeIdDef = typeSer.writeTypePrefix(g, ctxt, typeSer.typeId(value, JsonToken.START_ARRAY));
        writeContentsAsArray(value, g);
    } else {
        typeIdDef = typeSer.writeTypePrefix(g, ctxt, typeSer.typeId(value, JsonToken.VALUE_STRING));
        char[] chars = value.toArray();
        g.writeString(chars, 0, chars.length);
    }
    typeSer.writeTypeSuffix(g, ctxt, typeIdDef);
}
 
Example #11
Source File: LocalDateSerializer.java    From jackson-modules-java8 with Apache License 2.0 6 votes vote down vote up
@Override
public void serializeWithType(LocalDate value, JsonGenerator g,
        SerializerProvider ctxt, TypeSerializer typeSer) throws IOException
{
    WritableTypeId typeIdDef = typeSer.writeTypePrefix(g, ctxt,
            typeSer.typeId(value, serializationShape(ctxt)));
    // need to write out to avoid double-writing array markers
    switch (typeIdDef.valueShape) {
    case START_ARRAY:
        _serializeAsArrayContents(value, g, ctxt);
        break;
    case VALUE_NUMBER_INT:
        g.writeNumber(value.toEpochDay());
        break;
    default:
        g.writeString((_formatter == null) ? value.toString() : value.format(_formatter));
    }
    typeSer.writeTypeSuffix(g, ctxt, typeIdDef);
}
 
Example #12
Source File: LocalTimeSerializer.java    From jackson-modules-java8 with Apache License 2.0 6 votes vote down vote up
@Override
public void serializeWithType(LocalTime value, JsonGenerator g,
        SerializerProvider ctxt, TypeSerializer typeSer) throws IOException
{
    WritableTypeId typeIdDef = typeSer.writeTypePrefix(g, ctxt,
            typeSer.typeId(value, serializationShape(ctxt)));
    // need to write out to avoid double-writing array markers
    if (typeIdDef.valueShape == JsonToken.START_ARRAY) {
        _serializeAsArrayContents(value, g, ctxt);
    } else {
        DateTimeFormatter dtf = _formatter;
        if (dtf == null) {
            dtf = _defaultFormatter();
        }
        g.writeString(value.format(dtf));
    }
    typeSer.writeTypeSuffix(g, ctxt, typeIdDef);
}
 
Example #13
Source File: LocalDateTimeSerializer.java    From jackson-modules-java8 with Apache License 2.0 6 votes vote down vote up
@Override
public void serializeWithType(LocalDateTime value, JsonGenerator g, SerializerProvider ctxt,
        TypeSerializer typeSer) throws IOException
{
    WritableTypeId typeIdDef = typeSer.writeTypePrefix(g, ctxt,
            typeSer.typeId(value, serializationShape(ctxt)));
    // need to write out to avoid double-writing array markers
    if (typeIdDef.valueShape == JsonToken.START_ARRAY) {
        _serializeAsArrayContents(value, g, ctxt);
    } else {
        DateTimeFormatter dtf = _formatter;
        if (dtf == null) {
            dtf = _defaultFormatter();
        }
        g.writeString(value.format(dtf));
    }
    typeSer.writeTypeSuffix(g, ctxt, typeIdDef);
}
 
Example #14
Source File: PrimitiveIterableSerializer.java    From jackson-datatypes-collections with Apache License 2.0 5 votes vote down vote up
@Override
public void serializeWithType(C value, JsonGenerator g, SerializerProvider ctxt, TypeSerializer typeSer)
        throws IOException {
    g.setCurrentValue(value);
    WritableTypeId typeIdDef = typeSer.writeTypePrefix(g, ctxt, typeSer.typeId(value, JsonToken.START_ARRAY));
    serializeContents(value, g);
    typeSer.writeTypeSuffix(g, ctxt, typeIdDef);
}
 
Example #15
Source File: StringCollectionSerializer.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void serializeWithType(Collection<String> value, JsonGenerator g,
        SerializerProvider provider, TypeSerializer typeSer)
    throws IOException
{
    g.setCurrentValue(value);
    WritableTypeId typeIdDef = typeSer.writeTypePrefix(g,
            typeSer.typeId(value, JsonToken.START_ARRAY));
    serializeContents(value, g, provider);
    typeSer.writeTypeSuffix(g, typeIdDef);
}
 
Example #16
Source File: ValueNode.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void serializeWithType(JsonGenerator g, SerializerProvider provider,
        TypeSerializer typeSer)
    throws IOException
{
    WritableTypeId typeIdDef = typeSer.writeTypePrefix(g,
            typeSer.typeId(this, asToken()));
    serialize(g, provider);
    typeSer.writeTypeSuffix(g, typeIdDef);
}
 
Example #17
Source File: TypeBase.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void serializeWithType(JsonGenerator g, SerializerProvider provider,
        TypeSerializer typeSer)
    throws IOException
{
    WritableTypeId typeIdDef = new WritableTypeId(this, JsonToken.VALUE_STRING);
    typeSer.writeTypePrefix(g, typeIdDef);
    this.serialize(g, provider);
    typeSer.writeTypeSuffix(g, typeIdDef);
}
 
Example #18
Source File: NioPathSerializer.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void serializeWithType(Path value, JsonGenerator g,
        SerializerProvider provider, TypeSerializer typeSer) throws IOException
{
    // Better ensure we don't use specific sub-classes:
    WritableTypeId typeIdDef = typeSer.writeTypePrefix(g,
            typeSer.typeId(value, Path.class, JsonToken.VALUE_STRING));
    serialize(value, g, provider);
    typeSer.writeTypeSuffix(g, typeIdDef);
}
 
Example #19
Source File: JsonGenerator.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public WritableTypeId writeTypeSuffix(WritableTypeId typeIdDef) throws IOException
{
    final JsonToken valueShape = typeIdDef.valueShape;
    // First: does value need closing?
    if (valueShape == JsonToken.START_OBJECT) {
        writeEndObject();
    } else if (valueShape == JsonToken.START_ARRAY) {
        writeEndArray();
    }

    if (typeIdDef.wrapperWritten) {
        switch (typeIdDef.include) {
        case WRAPPER_ARRAY:
            writeEndArray();
            break;
        case PARENT_PROPERTY:
            // unusually, need to output AFTER value. And no real wrapper...
            {
                Object id = typeIdDef.id;
                String idStr = (id instanceof String) ? (String) id : String.valueOf(id);
                writeStringField(typeIdDef.asProperty, idStr);
            }
            break;
        case METADATA_PROPERTY:
        case PAYLOAD_PROPERTY:
            // no actual wrapper; included within Object itself
            break;
        case WRAPPER_OBJECT:
        default: // should never occur but...
            writeEndObject();
            break;
        }
    }
    return typeIdDef;
}
 
Example #20
Source File: RefRefMapSerializer.java    From jackson-datatypes-collections with Apache License 2.0 5 votes vote down vote up
@Override
public void serializeWithType(
        T value, JsonGenerator gen,
        SerializerProvider ctxt, TypeSerializer typeSer
) throws IOException {
    gen.setCurrentValue(value);
    WritableTypeId typeIdDef = typeSer.writeTypePrefix(gen, ctxt,
            typeSer.typeId(value, JsonToken.START_OBJECT));
    if (!isEmpty(ctxt, value)) {
        serializeFields(value, gen, ctxt);
    }
    typeSer.writeTypeSuffix(gen, ctxt, typeIdDef);
}
 
Example #21
Source File: PrimitiveMapSerializer.java    From jackson-datatypes-collections with Apache License 2.0 5 votes vote down vote up
@Override
public void serializeWithType(T value, JsonGenerator gen, SerializerProvider ctxt, TypeSerializer typeSer)
        throws IOException {
    WritableTypeId typeIdDef = typeSer.writeTypePrefix(
            gen, ctxt, typeSer.typeId(value, JsonToken.START_OBJECT));
    serializeEntries(value, gen, ctxt);
    typeSer.writeTypeSuffix(gen, ctxt, typeIdDef);
}
 
Example #22
Source File: MonthDaySerializer.java    From jackson-modules-java8 with Apache License 2.0 5 votes vote down vote up
@Override
public void serializeWithType(MonthDay value, JsonGenerator g,
        SerializerProvider ctxt, TypeSerializer typeSer) throws IOException
{
    WritableTypeId typeIdDef = typeSer.writeTypePrefix(g, ctxt,
            typeSer.typeId(value, serializationShape(ctxt)));
    // need to write out to avoid double-writing array markers
    if (typeIdDef.valueShape == JsonToken.START_ARRAY) {
        _serializeAsArrayContents(value, g, ctxt);
    } else {
        g.writeString((_formatter == null) ? value.toString() : value.format(_formatter));
    }
    typeSer.writeTypeSuffix(g, ctxt, typeIdDef);
}
 
Example #23
Source File: ByteIterableSerializer.java    From jackson-datatypes-collections with Apache License 2.0 5 votes vote down vote up
@Override
public void serializeWithType(
        ByteIterable value, JsonGenerator g, SerializerProvider ctxt,
        TypeSerializer typeSer
)
        throws IOException {
    WritableTypeId typeIdDef = typeSer.writeTypePrefix(g, ctxt,
            typeSer.typeId(value, JsonToken.VALUE_EMBEDDED_OBJECT));
    byte[] arr = value.toArray();
    g.writeBinary(ctxt.getConfig().getBase64Variant(), arr, 0, arr.length);
    typeSer.writeTypeSuffix(g, ctxt, typeIdDef);
}
 
Example #24
Source File: ZoneIdSerializer.java    From jackson-modules-java8 with Apache License 2.0 5 votes vote down vote up
@Override
public void serializeWithType(Object value, JsonGenerator g,
        SerializerProvider ctxt, TypeSerializer typeSer) throws IOException
{
    // Better ensure we don't use specific sub-classes:
    WritableTypeId typeIdDef = typeSer.writeTypePrefix(g, ctxt,
            typeSer.typeId(value, ZoneId.class, JsonToken.VALUE_STRING));
    serialize(value, g, ctxt);
    typeSer.writeTypeSuffix(g, ctxt, typeIdDef);
}
 
Example #25
Source File: RangeSerializer.java    From jackson-datatypes-collections with Apache License 2.0 5 votes vote down vote up
@Override
public void serializeWithType(Range<?> value, JsonGenerator gen, SerializerProvider ctxt,
        TypeSerializer typeSer)
    throws IOException
{
    gen.setCurrentValue(value);
    WritableTypeId typeIdDef = typeSer.writeTypePrefix(gen, ctxt,
            typeSer.typeId(value, JsonToken.START_OBJECT));
    _writeContents(value, gen, ctxt);
    typeSer.writeTypeSuffix(gen, ctxt, typeIdDef);
}
 
Example #26
Source File: OffsetTimeSerializer.java    From jackson-modules-java8 with Apache License 2.0 5 votes vote down vote up
@Override
public void serializeWithType(OffsetTime value, JsonGenerator g, SerializerProvider ctxt,
        TypeSerializer typeSer) throws IOException
{
    WritableTypeId typeIdDef = typeSer.writeTypePrefix(g, ctxt,
            typeSer.typeId(value, serializationShape(ctxt)));
    // need to write out to avoid double-writing array markers
    if (typeIdDef.valueShape == JsonToken.START_ARRAY) {
        _serializeAsArrayContents(value, g, ctxt);
    } else {
        String str = (_formatter == null) ? value.toString() : value.format(_formatter);
        g.writeString(str);
    }
    typeSer.writeTypeSuffix(g, ctxt, typeIdDef);
}
 
Example #27
Source File: TableSerializer.java    From jackson-datatypes-collections with Apache License 2.0 5 votes vote down vote up
@Override
public void serializeWithType(final Table<?, ?, ?> value,
        final JsonGenerator gen, final SerializerProvider ctxt,
        final TypeSerializer typeSer) throws IOException
{
    gen.setCurrentValue(value);
    WritableTypeId typeIdDef = typeSer.writeTypePrefix(gen, ctxt,
            typeSer.typeId(value, JsonToken.START_OBJECT));
    serializeFields(value, gen, ctxt);
    typeSer.writeTypeSuffix(gen, ctxt, typeIdDef);
}
 
Example #28
Source File: ContainerSerializerBase.java    From jackson-datatypes-collections with Apache License 2.0 5 votes vote down vote up
@Override
public void serializeWithType(T value, JsonGenerator gen, SerializerProvider ctxt,
        TypeSerializer typeSer)
    throws IOException
{
    gen.setCurrentValue(value);
    WritableTypeId typeIdDef = typeSer.writeTypePrefix(gen, ctxt,
            typeSer.typeId(value, JsonToken.START_ARRAY));
    serializeContents(value, gen, ctxt);
    typeSer.writeTypeSuffix(gen, ctxt, typeIdDef);
}
 
Example #29
Source File: HppcContainerSerializers.java    From jackson-datatypes-collections with Apache License 2.0 5 votes vote down vote up
@Override
public void serializeWithType(ByteContainer value, JsonGenerator gen, SerializerProvider ctxt,
        TypeSerializer typeSer)
    throws IOException
{
    gen.setCurrentValue(value);
    WritableTypeId typeIdDef = typeSer.writeTypePrefix(gen, ctxt,
            typeSer.typeId(value, JsonToken.VALUE_EMBEDDED_OBJECT));
    serializeContents(value, gen, ctxt);
    typeSer.writeTypeSuffix(gen, ctxt, typeIdDef);
}
 
Example #30
Source File: JSR310SerializerBase.java    From jackson-modules-java8 with Apache License 2.0 5 votes vote down vote up
@Override
public void serializeWithType(T value, JsonGenerator g, SerializerProvider ctxt,
        TypeSerializer typeSer) throws IOException
{
    WritableTypeId typeIdDef = typeSer.writeTypePrefix(g, ctxt,
            typeSer.typeId(value, serializationShape(ctxt)));
    serialize(value, g, ctxt);
    typeSer.writeTypeSuffix(g, ctxt, typeIdDef);
}