Java Code Examples for com.fasterxml.jackson.databind.jsontype.TypeSerializer#writeTypePrefix()
The following examples show how to use
com.fasterxml.jackson.databind.jsontype.TypeSerializer#writeTypePrefix() .
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: LocalDateTimeSerializer.java From jackson-modules-java8 with Apache License 2.0 | 6 votes |
@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 2
Source File: MultimapSerializer.java From jackson-datatypes-collections with Apache License 2.0 | 6 votes |
@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 3
Source File: BeanSerializerBase.java From lams with GNU General Public License v2.0 | 6 votes |
@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 4
Source File: MapSerializer.java From lams with GNU General Public License v2.0 | 6 votes |
@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 5
Source File: LocalTimeSerializer.java From jackson-modules-java8 with Apache License 2.0 | 6 votes |
@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 6
Source File: NioPathSerializer.java From lams with GNU General Public License v2.0 | 5 votes |
@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 7
Source File: YearMonthSerializer.java From jackson-modules-java8 with Apache License 2.0 | 5 votes |
@Override public void serializeWithType(YearMonth 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 8
Source File: StdScalarSerializer.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Default implementation will write type prefix, call regular serialization * method (since assumption is that value itself does not need JSON * Array or Object start/end markers), and then write type suffix. * This should work for most cases; some sub-classes may want to * change this behavior. */ @Override public void serializeWithType(T value, JsonGenerator g, SerializerProvider provider, TypeSerializer typeSer) throws IOException { // NOTE: need not really be string; just indicates "scalar of some kind" WritableTypeId typeIdDef = typeSer.writeTypePrefix(g, typeSer.typeId(value, JsonToken.VALUE_STRING)); serialize(value, g, provider); typeSer.writeTypeSuffix(g, typeIdDef); }
Example 9
Source File: RefRefMapSerializer.java From jackson-datatypes-collections with Apache License 2.0 | 5 votes |
@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 10
Source File: ZoneIdSerializer.java From jackson-modules-java8 with Apache License 2.0 | 5 votes |
@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 11
Source File: TokenBufferSerializer.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Implementing typed output for contents of a TokenBuffer is very tricky, * since we do not know for sure what its contents might look like (or, rather, * we do know when serializing, but not necessarily when deserializing!) * One possibility would be to check the current token, and use that to * determine if we would output JSON Array, Object or scalar value. *<p> * Note that we just claim it is scalar; this should work ok and is simpler * than doing introspection on both serialization and deserialization. */ @Override public final void serializeWithType(TokenBuffer value, JsonGenerator g, SerializerProvider provider, TypeSerializer typeSer) throws IOException { // 28-Jun-2017, tatu: As per javadoc, not sure what to report as likely shape. Could // even look into first actual token inside... but, for now let's keep it simple WritableTypeId typeIdDef = typeSer.writeTypePrefix(g, typeSer.typeId(value, JsonToken.VALUE_EMBEDDED_OBJECT)); serialize(value, g, provider); typeSer.writeTypeSuffix(g, typeIdDef); }
Example 12
Source File: TypeBase.java From lams with GNU General Public License v2.0 | 5 votes |
@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 13
Source File: PrimitiveMapSerializer.java From jackson-datatypes-collections with Apache License 2.0 | 5 votes |
@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 14
Source File: ArrayNode.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public void serializeWithType(JsonGenerator g, SerializerProvider provider, TypeSerializer typeSer) throws IOException { WritableTypeId typeIdDef = typeSer.writeTypePrefix(g, typeSer.typeId(this, JsonToken.START_ARRAY)); for (JsonNode n : _children) { ((BaseJsonNode)n).serialize(g, provider); } typeSer.writeTypeSuffix(g, typeIdDef); }
Example 15
Source File: NodeSerializer.java From healenium-web with Apache License 2.0 | 5 votes |
@Override public void serializeWithType(Node value, JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { WritableTypeId typeId = typeSer.typeId(value, Node.class, JsonToken.START_OBJECT); typeSer.writeTypePrefix(gen, typeId); serialize(value, gen, serializers); typeSer.writeTypeSuffix(gen, typeId); }
Example 16
Source File: JSR310SerializerBase.java From jackson-modules-java8 with Apache License 2.0 | 5 votes |
@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); }
Example 17
Source File: MonthDaySerializer.java From jackson-modules-java8 with Apache License 2.0 | 5 votes |
@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 18
Source File: HppcContainerSerializers.java From jackson-datatypes-collections with Apache License 2.0 | 5 votes |
@Override public void serializeWithType(CharContainer value, JsonGenerator gen, SerializerProvider ctxt, TypeSerializer typeSer) throws IOException { gen.setCurrentValue(value); WritableTypeId typeIdDef = typeSer.writeTypePrefix(gen, ctxt, typeSer.typeId(value, JsonToken.VALUE_STRING)); serializeContents(value, gen, ctxt); typeSer.writeTypeSuffix(gen, ctxt, typeIdDef); }
Example 19
Source File: RangeSerializer.java From jackson-datatypes-collections with Apache License 2.0 | 5 votes |
@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 20
Source File: ByteIterableSerializer.java From jackson-datatypes-collections with Apache License 2.0 | 5 votes |
@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); }