Java Code Examples for com.fasterxml.jackson.databind.SerializerProvider#findValueSerializer()
The following examples show how to use
com.fasterxml.jackson.databind.SerializerProvider#findValueSerializer() .
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: BigDecimalSpecifySerialize.java From jframework with Apache License 2.0 | 6 votes |
@Override public JsonSerializer<?> createContextual(SerializerProvider prov, BeanProperty property) throws JsonMappingException { // 为空直接跳过 if (property == null) { return prov.findNullValueSerializer(property); } // 非 BigDecimal 类直接跳过 if (Objects.equals(property.getType().getRawClass(), BigDecimal.class)) { BigDecimalSpecify doubleSpecify = property.getAnnotation(BigDecimalSpecify.class); if (doubleSpecify == null) { doubleSpecify = property.getContextAnnotation(BigDecimalSpecify.class); } // 如果能得到注解,就将注解的 value 传入 BigDecimalSpecifySerialize if (doubleSpecify != null) { return new BigDecimalSpecifySerialize(doubleSpecify.value()); } } return prov.findValueSerializer(property.getType(), property); }
Example 2
Source File: SensitiveSerialize.java From Resource with GNU General Public License v3.0 | 6 votes |
@Override public JsonSerializer<?> createContextual(SerializerProvider prov, BeanProperty property) throws JsonMappingException { if (property != null) { // 为空直接跳过 if (Objects.equals(property.getType().getRawClass(), String.class)) { // 非 String 类直接跳过 SensitiveInfo sensitiveInfo = property.getAnnotation(SensitiveInfo.class); if (sensitiveInfo == null) { sensitiveInfo = property.getContextAnnotation(SensitiveInfo.class); } if (sensitiveInfo != null) { // 如果能得到注解,就将注解的 value 传入 SensitiveInfoSerialize SensitiveSerialize serialize = new SensitiveSerialize(); serialize.type = sensitiveInfo.value(); return serialize; } } return prov.findValueSerializer(property.getType(), property); } return prov.findNullValueSerializer(property); }
Example 3
Source File: UnwrappingBeanPropertyWriter.java From lams with GNU General Public License v2.0 | 6 votes |
@Override protected JsonSerializer<Object> _findAndAddDynamic(PropertySerializerMap map, Class<?> type, SerializerProvider provider) throws JsonMappingException { JsonSerializer<Object> serializer; if (_nonTrivialBaseType != null) { JavaType subtype = provider.constructSpecializedType(_nonTrivialBaseType, type); serializer = provider.findValueSerializer(subtype, this); } else { serializer = provider.findValueSerializer(type, this); } NameTransformer t = _nameTransformer; if (serializer.isUnwrappingSerializer()) { t = NameTransformer.chainedTransformer(t, ((UnwrappingBeanSerializer) serializer)._nameTransformer); } serializer = serializer.unwrappingSerializer(t); _dynamicSerializers = _dynamicSerializers.newWith(type, serializer); return serializer; }
Example 4
Source File: ToStringSerializer.java From kafka-webview with MIT License | 6 votes |
@Override public void serialize( final Object value, final JsonGenerator gen, final SerializerProvider serializers ) throws IOException { if (value == null) { gen.writeString(""); return; } // See if we have a serializer that is NOT the unknown serializer final JsonSerializer serializer = serializers.findValueSerializer(value.getClass()); if (serializer != null && !(serializer instanceof UnknownSerializer)) { serializer.serialize(value, gen, serializers); return; } gen.writeString(value.toString()); }
Example 5
Source File: SensitiveInfoSerialize.java From pre with GNU General Public License v3.0 | 6 votes |
@Override public JsonSerializer<?> createContextual(final SerializerProvider serializerProvider, final BeanProperty beanProperty) throws JsonMappingException { // 为空直接跳过 if (beanProperty != null) { // 非 String 类直接跳过 if (Objects.equals(beanProperty.getType().getRawClass(), String.class)) { SensitiveInfo sensitiveInfo = beanProperty.getAnnotation(SensitiveInfo.class); if (sensitiveInfo == null) { sensitiveInfo = beanProperty.getContextAnnotation(SensitiveInfo.class); } // 如果能得到注解,就将注解的 value 传入 SensitiveInfoSerialize if (sensitiveInfo != null) { return new SensitiveInfoSerialize(sensitiveInfo.value()); } } return serializerProvider.findValueSerializer(beanProperty.getType(), beanProperty); } return serializerProvider.findNullValueSerializer(beanProperty); }
Example 6
Source File: StdCallbackContext.java From cloudformation-cli-java-plugin with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private void writeObject(Object val, JsonGenerator gen, SerializerProvider serializers) throws IOException { if (val == null) { gen.writeNull(); return; } // Primitive if (val instanceof String || val instanceof Number || val instanceof Boolean) { gen.writeObject(val); return; } // Encode object type information gen.writeStartArray(); Class<?> type = val.getClass(); // write class name first gen.writeString(type.getName()); // the write value next if (val instanceof Collection<?>) { writeCollection((Collection<?>) val, gen, serializers); } else if (val instanceof Map<?, ?>) { Map<?, ?> map = (Map<?, ?>) val; writeMap(map, gen, serializers); } else { JsonSerializer<Object> serializer = serializers.findValueSerializer(type); serializer.serialize(val, gen, serializers); } // end marker gen.writeEndArray(); }
Example 7
Source File: HalCollectionWrapperJacksonSerializer.java From quarkus with Apache License 2.0 | 5 votes |
private void writeEmbedded(HalCollectionWrapper wrapper, JsonGenerator generator, SerializerProvider serializers) throws IOException { JsonSerializer<Object> entitySerializer = serializers.findValueSerializer(HalEntityWrapper.class); generator.writeFieldName("_embedded"); generator.writeStartObject(); generator.writeFieldName(wrapper.getCollectionName()); generator.writeStartArray(wrapper.getCollection().size()); for (Object entity : wrapper.getCollection()) { entitySerializer.serialize(new HalEntityWrapper(entity), generator, serializers); } generator.writeEndArray(); generator.writeEndObject(); }
Example 8
Source File: SdkPojoSerializer.java From cloudformation-cli-java-plugin with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private void writeObject(Object value, SdkField<?> sdkField, JsonGenerator gen, SerializerProvider serializers) throws IOException { MarshallingType<?> type = sdkField.marshallingType(); if (type.equals(MarshallingType.BOOLEAN)) { gen.writeBoolean((Boolean) value); } else if (type.equals(MarshallingType.DOUBLE)) { gen.writeNumber((Double) value); } else if (type.equals(MarshallingType.INTEGER)) { gen.writeNumber((Integer) value); } else if (type.equals(MarshallingType.FLOAT)) { gen.writeNumber((Float) value); } else if (type.equals(MarshallingType.STRING)) { gen.writeString((String) value); } else if (type.equals(MarshallingType.BIG_DECIMAL)) { gen.writeNumber((BigDecimal) value); } else if (type.equals(MarshallingType.SDK_BYTES)) { gen.writeBinary(((SdkBytes) value).asByteArray()); } else if (type.equals(MarshallingType.INSTANT)) { JsonSerializer<Object> serializer = serializers.findValueSerializer(Instant.class); serializer.serialize(value, gen, serializers); } else if (type.equals(MarshallingType.LONG)) { gen.writeNumber((Long) value); } else if (type.equals(MarshallingType.SDK_POJO)) { writeSdkPojo((SdkPojo) value, gen, serializers); } else if (type.equals(MarshallingType.LIST)) { writeSdkList((Collection<Object>) value, sdkField, gen, serializers); } else if (type.equals(MarshallingType.MAP)) { writeSdkMap((Map<String, Object>) value, sdkField, gen, serializers); } }
Example 9
Source File: PropertySerializerMap.java From lams with GNU General Public License v2.0 | 5 votes |
public final SerializerAndMapResult findAndAddSecondarySerializer(JavaType type, SerializerProvider provider, BeanProperty property) throws JsonMappingException { JsonSerializer<Object> serializer = provider.findValueSerializer(type, property); return new SerializerAndMapResult(serializer, newWith(type.getRawClass(), serializer)); }
Example 10
Source File: CustomMessageElementVisitor.java From caravan with Apache License 2.0 | 5 votes |
private CustomProtoBufSchemaVisitor acceptTypeElement(SerializerProvider provider, JavaType type, DefinedTypeElementBuilders definedTypeElementBuilders, boolean isNested) throws JsonMappingException { JsonSerializer<Object> serializer = provider.findValueSerializer(type, null); CustomProtoBufSchemaVisitor visitor = new CustomProtoBufSchemaVisitor(provider, definedTypeElementBuilders, isNested, customizedDataTypes); serializer.acceptJsonFormatVisitor(visitor, type); return visitor; }
Example 11
Source File: JsonValues.java From DCMonitor with MIT License | 5 votes |
@Override public void serialize( JsonValues value, JsonGenerator jgen, SerializerProvider provider ) throws IOException, JsonProcessingException { JsonSerializer<Object> serializer = provider.findValueSerializer(value.values.getClass(), null); serializer.serialize(value.values, jgen, provider); }
Example 12
Source File: ResourcesMapper.java From mobilecloud-15 with Apache License 2.0 | 5 votes |
@Override public void serialize(Resources value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { // Extracted the actual data inside of the Resources object // that we care about (e.g., the list of Video objects) Object content = value.getContent(); // Instead of all of the Resources member variables, etc. // Just mashall the actual content (Videos) into the JSON JsonSerializer<Object> s = provider.findValueSerializer( content.getClass(), null); s.serialize(content, jgen, provider); }
Example 13
Source File: ResourcesMapper.java From mobilecloud-15 with Apache License 2.0 | 5 votes |
@Override public void serialize(Resources value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { // Extracted the actual data inside of the Resources object // that we care about (e.g., the list of Video objects) Object content = value.getContent(); // Instead of all of the Resources member variables, etc. // Just mashall the actual content (Videos) into the JSON JsonSerializer<Object> s = provider.findValueSerializer( content.getClass(), null); s.serialize(content, jgen, provider); }
Example 14
Source File: ResourcesMapper.java From mobilecloud-15 with Apache License 2.0 | 5 votes |
@Override public void serialize(Resources value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { // Extracted the actual data inside of the Resources object // that we care about (e.g., the list of Video objects) Object content = value.getContent(); // Instead of all of the Resources member variables, etc. // Just mashall the actual content (Videos) into the JSON JsonSerializer<Object> s = provider.findValueSerializer( content.getClass(), null); s.serialize(content, jgen, provider); }
Example 15
Source File: ResourcesMapper.java From mobilecloud-15 with Apache License 2.0 | 5 votes |
@Override public void serialize(Resources value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { // Extracted the actual data inside of the Resources object // that we care about (e.g., the list of Video objects) Object content = value.getContent(); // Instead of all of the Resources member variables, etc. // Just mashall the actual content (Videos) into the JSON JsonSerializer<Object> s = provider.findValueSerializer( content.getClass(), null); s.serialize(content, jgen, provider); }
Example 16
Source File: ResourcesMapper.java From mobilecloud-15 with Apache License 2.0 | 5 votes |
@Override public void serialize(Resources value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { // Extracted the actual data inside of the Resources object // that we care about (e.g., the list of Video objects) Object content = value.getContent(); // Instead of all of the Resources member variables, etc. // Just mashall the actual content (Videos) into the JSON JsonSerializer<Object> s = provider.findValueSerializer( content.getClass(), null); s.serialize(content, jgen, provider); }
Example 17
Source File: DynamicFilters.java From proctor with Apache License 2.0 | 4 votes |
@Override public void serialize(final JsonGenerator gen, final SerializerProvider serializers) throws IOException { final JsonSerializer<Object> serializer = serializers.findValueSerializer(DynamicFilter[].class); serializer.serialize(filters.toArray(), gen, serializers); }
Example 18
Source File: ProtobufSerializer.java From jackson-datatype-protobuf with Apache License 2.0 | 4 votes |
protected void writeValue( FieldDescriptor field, Object value, JsonGenerator generator, SerializerProvider serializerProvider ) throws IOException { switch (field.getJavaType()) { case INT: generator.writeNumber((Integer) value); break; case LONG: generator.writeNumber((Long) value); break; case FLOAT: generator.writeNumber((Float) value); break; case DOUBLE: generator.writeNumber((Double) value); break; case BOOLEAN: generator.writeBoolean((Boolean) value); break; case STRING: generator.writeString((String) value); break; case ENUM: EnumValueDescriptor enumDescriptor = (EnumValueDescriptor) value; // special-case NullValue if (NULL_VALUE_FULL_NAME.equals(enumDescriptor.getType().getFullName())) { generator.writeNull(); } else if (writeEnumsUsingIndex(serializerProvider)) { generator.writeNumber(enumDescriptor.getNumber()); } else { generator.writeString(enumDescriptor.getName()); } break; case BYTE_STRING: generator.writeString(serializerProvider.getConfig().getBase64Variant().encode(((ByteString) value).toByteArray())); break; case MESSAGE: Class<?> subType = value.getClass(); JsonSerializer<Object> serializer = serializerCache.get(subType); if (serializer == null) { serializer = serializerProvider.findValueSerializer(value.getClass(), null); serializerCache.put(subType, serializer); } serializer.serialize(value, generator, serializerProvider); break; default: throw unrecognizedType(field, generator); } }
Example 19
Source File: DynamicFilters.java From proctor with Apache License 2.0 | 4 votes |
@Override public void serializeWithType(final JsonGenerator gen, final SerializerProvider serializers, final TypeSerializer typeSer) throws IOException { final JsonSerializer<Object> serializer = serializers.findValueSerializer(DynamicFilter[].class); serializer.serializeWithType(filters.toArray(), gen, serializers, typeSer); }
Example 20
Source File: PropertySerializerMap.java From lams with GNU General Public License v2.0 | 3 votes |
/** * Method called if initial lookup fails, when looking for a non-primary * serializer (one that is not directly attached to a property). * Will both find serializer * and construct new map instance if warranted, and return both. * * @since 2.3 * * @throws JsonMappingException */ public final SerializerAndMapResult findAndAddSecondarySerializer(Class<?> type, SerializerProvider provider, BeanProperty property) throws JsonMappingException { JsonSerializer<Object> serializer = provider.findValueSerializer(type, property); return new SerializerAndMapResult(serializer, newWith(type, serializer)); }