com.fasterxml.jackson.databind.SerializationConfig Java Examples

The following examples show how to use com.fasterxml.jackson.databind.SerializationConfig. 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 Project: crnk-framework   Author: crnk-project   File: AnnotatedClassBuilder.java    License: Apache License 2.0 6 votes vote down vote up
public static AnnotatedClass build(final Class<?> declaringClass, final SerializationConfig serializationConfig) {

		for (final Method method : AnnotatedClass.class.getMethods()) {
			if (CONSTRUCT_METHOD_NAME.equals(method.getName()) &&
					method.getParameterTypes().length == 3) {

				return ExceptionUtil.wrapCatchedExceptions(new Callable<AnnotatedClass>() {
					@Override
					public AnnotatedClass call() throws Exception {
						return buildAnnotatedClass(method, declaringClass, serializationConfig);
					}
				}, "Exception while building AnnotatedClass");
			}
		}
		throw new IllegalStateException(CANNOT_FIND_PROPER_METHOD);
	}
 
Example #2
Source Project: crnk-framework   Author: crnk-project   File: JacksonResourceFieldInformationProvider.java    License: Apache License 2.0 6 votes vote down vote up
protected Optional<String> getName(Method method) {
	ObjectMapper objectMapper = context.getObjectMapper();
	SerializationConfig serializationConfig = objectMapper.getSerializationConfig();
	if (serializationConfig != null && serializationConfig.getPropertyNamingStrategy() != null) {
		String name = ClassUtils.getGetterFieldName(method);
		Annotation[] declaredAnnotations = method.getDeclaredAnnotations();
		AnnotationMap annotationMap = buildAnnotationMap(declaredAnnotations);

		int paramsLength = method.getParameterAnnotations().length;
		AnnotationMap[] paramAnnotations = new AnnotationMap[paramsLength];
		for (int i = 0; i < paramsLength; i++) {
			AnnotationMap parameterAnnotationMap = buildAnnotationMap(method.getParameterAnnotations()[i]);
			paramAnnotations[i] = parameterAnnotationMap;
		}

		AnnotatedClass annotatedClass = AnnotatedClassBuilder.build(method.getDeclaringClass(), serializationConfig);
		AnnotatedMethod annotatedField = AnnotatedMethodBuilder.build(annotatedClass, method, annotationMap, paramAnnotations);
		return Optional.of(serializationConfig.getPropertyNamingStrategy().nameForGetterMethod(serializationConfig, annotatedField, name));
	}
	return Optional.empty();
}
 
Example #3
Source Project: bboss-elasticsearch   Author: bbossgroups   File: EntityCustomSerializationFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void processViews(SerializationConfig config, BeanSerializerBuilder builder) {
	super.processViews(config, builder);
	// ignore fields only for concrete class
	// note, that you can avoid or change this check
	Class<?> beanClass = builder.getBeanDescription().getBeanClass();
	ClassUtil.ClassInfo classInfo = ClassUtil.getClassInfo(beanClass);
	// if (builder.getBeanDescription().getBeanClass().equals(Entity.class))
	// {
	// get original writer
	List<BeanPropertyWriter> originalWriters = builder.getProperties();
	// create actual writers
	List<BeanPropertyWriter> writers = new ArrayList<BeanPropertyWriter>();
	String[] fs = this._getFilterFields(classInfo);
	for (BeanPropertyWriter writer : originalWriters) {
		final String propName = writer.getName();
		// if it isn't ignored field, add to actual writers list
		boolean find = isFilterField(  classInfo,  propName,  fs);

		if(!find){
			writers.add(writer);
		}
	}
	builder.setProperties(writers);
}
 
Example #4
Source Project: tutorials   Author: eugenp   File: JacksonDynamicIgnoreUnitTest.java    License: MIT License 6 votes vote down vote up
@Before
public void setUp() {
    mapper.setSerializationInclusion(Include.NON_EMPTY);
    mapper.registerModule(new SimpleModule() {
        @Override
        public void setupModule(final SetupContext context) {
            super.setupModule(context);
            context.addBeanSerializerModifier(new BeanSerializerModifier() {
                @Override
                public JsonSerializer<?> modifySerializer(final SerializationConfig config, final BeanDescription beanDesc, final JsonSerializer<?> serializer) {
                    if (Hidable.class.isAssignableFrom(beanDesc.getBeanClass())) {
                        return new HidableSerializer((JsonSerializer<Object>) serializer);
                    }
                    return serializer;
                }
            });
        }
    });
}
 
Example #5
Source Project: log4j2-elasticsearch   Author: rfoltyns   File: VirtualPropertiesWriterTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void overridenFixAccessIsNoop() {

    // given
    ObjectMapper objectMapper = new ObjectMapper();
    SerializationConfig config = objectMapper.getSerializationConfig();

    VirtualPropertiesWriter writer = spy(new VirtualPropertiesWriter(
            new VirtualProperty[0],
            mock(ValueResolver.class)
    ));

    // when
    writer.fixAccess(config);

    // then
    verify(writer, never()).getMember();

}
 
Example #6
Source Project: Rosetta   Author: HubSpot   File: StoredAsJsonBeanSerializerModifier.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public List<BeanPropertyWriter> changeProperties(SerializationConfig config, BeanDescription beanDesc, List<BeanPropertyWriter> beanProperties) {
  for (BeanPropertyWriter beanProperty : beanProperties) {
    StoredAsJson storedAsJson = beanProperty.getAnnotation(StoredAsJson.class);
    if (storedAsJson != null && !StoredAsJson.NULL.equals(storedAsJson.empty())) {
      final JsonSerializer<Object> nullSerializer;
      if (storedAsJson.binary()) {
        nullSerializer = new ConstantBinarySerializer(storedAsJson.empty());
      } else {
        nullSerializer = new ConstantSerializer(storedAsJson.empty());
      }

      beanProperty.assignNullSerializer(nullSerializer);
    }
  }

  return super.changeProperties(config, beanDesc, beanProperties);
}
 
Example #7
Source Project: bowman   Author: BlackPepperSoftware   File: JacksonClientModule.java    License: Apache License 2.0 6 votes vote down vote up
public JacksonClientModule() {
	setSerializerModifier(new BeanSerializerModifier() {

		@Override
		public List<BeanPropertyWriter> changeProperties(SerializationConfig config, BeanDescription beanDesc,
				List<BeanPropertyWriter> beanProperties) {
			
			for (BeanPropertyWriter writer : beanProperties) {
				if (writer.getAnnotation(LinkedResource.class) != null) {
					writer.assignSerializer(new LinkedResourceUriSerializer());
				}
			}
			
			return beanProperties;
		}
	});
	
	setMixInAnnotation(EntityModel.class, ResourceMixin.class);
	setMixInAnnotation(MethodHandler.class, MethodHandlerMixin.class);
}
 
Example #8
Source Project: armeria   Author: line   File: ThriftJacksonSerializers.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public JsonSerializer<?> findSerializer(SerializationConfig config, JavaType type,
                                        BeanDescription beanDesc) {

    final Class<?> rawType = type.getRawClass();
    if (TMessage.class.isAssignableFrom(rawType)) {
        return new TMessageJsonSerializer();
    }
    if (TBase.class.isAssignableFrom(rawType)) {
        return new TBaseJsonSerializer(useNamedEnums);
    }
    if (TApplicationException.class.isAssignableFrom(rawType)) {
        return new TApplicationExceptionJsonSerializer(useNamedEnums);
    }
    if (ThriftCall.class.isAssignableFrom(rawType)) {
        return new ThriftCallJsonSerializer(useNamedEnums);
    }
    if (ThriftReply.class.isAssignableFrom(rawType)) {
        return new ThriftReplyJsonSerializer(useNamedEnums);
    }
    return super.findSerializer(config, type, beanDesc);
}
 
Example #9
Source Project: vavr-jackson   Author: vavr-io   File: VavrSerializers.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public JsonSerializer<?> findCollectionLikeSerializer(SerializationConfig config,
                                                      CollectionLikeType collectionType, BeanDescription beanDesc,
                                                      TypeSerializer elementTypeSerializer, JsonSerializer<Object> elementValueSerializer) {
    Class<?> raw = collectionType.getRawClass();
    if (raw == CharSeq.class) {
        return new CharSeqSerializer(collectionType);
    }
    if (Seq.class.isAssignableFrom(raw)) {
        return new ArraySerializer<>(collectionType);
    }
    if (Set.class.isAssignableFrom(raw)) {
        return new ArraySerializer<>(collectionType);
    }
    if (PriorityQueue.class.isAssignableFrom(raw)) {
        return new ArraySerializer<>(collectionType);
    }
    return super.findCollectionLikeSerializer(config, collectionType, beanDesc, elementTypeSerializer, elementValueSerializer);
}
 
Example #10
Source Project: immutables   Author: immutables   File: JacksonCodecs.java    License: Apache License 2.0 5 votes vote down vote up
public static Serializers serializers(final CodecRegistry registry) {
  return new Serializers.Base() {
    @Override
    public JsonSerializer<?> findSerializer(SerializationConfig config, JavaType type, BeanDescription beanDesc) {
      try {
        Codec<?> codec = registry.get(type.getRawClass());
        return serializer(codec);
      } catch (CodecConfigurationException e) {
        return null;
      }
    }
  };
}
 
Example #11
Source Project: Moss   Author: SpringCloud   File: RegistrationBeanSerializerModifier.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public List<BeanPropertyWriter> changeProperties(SerializationConfig config,
                                                 BeanDescription beanDesc,
                                                 List<BeanPropertyWriter> beanProperties) {
    if (!Registration.class.isAssignableFrom(beanDesc.getBeanClass())) {
        return beanProperties;
    }

    beanProperties.stream()
                  .filter(beanProperty -> "metadata".equals(beanProperty.getName()))
                  .forEach(beanProperty -> beanProperty.assignSerializer(metadataSerializer));
    return beanProperties;
}
 
Example #12
Source Project: java-technology-stack   Author: codeEngraver   File: SpringHandlerInstantiatorTests.java    License: MIT License 5 votes vote down vote up
@Override
public TypeSerializer buildTypeSerializer(SerializationConfig config, JavaType baseType,
		Collection<NamedType> subtypes) {

	isAutowiredFiledInitialized = (this.capitalizer != null);
	return super.buildTypeSerializer(config, baseType, subtypes);
}
 
Example #13
Source Project: cola-cloud   Author: leecho   File: JacksonDictJsonModifier.java    License: MIT License 5 votes vote down vote up
@Override
public JsonSerializer<?> modifySerializer(SerializationConfig config,
                                          BeanDescription beanDesc, JsonSerializer<?> serializer) {
    JsonDict jsonDict = beanDesc.getBeanClass().getAnnotation(JsonDict.class);
    if(jsonDict != null){
        serializer = new JsonDictSerializer((BeanSerializerBase) serializer, dictClient,jsonDict);
    }
    return serializer;
}
 
Example #14
Source Project: cloudformation-cli-java-plugin   Author: aws-cloudformation   File: AWSServiceSerdeModule.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public JsonSerializer<?> findSerializer(SerializationConfig config, JavaType type, BeanDescription beanDesc) {
    if (SdkPojo.class.isAssignableFrom(type.getRawClass()) && !SdkBuilder.class.isAssignableFrom(type.getRawClass())) {
        return new SdkPojoSerializer();
    }
    return null;
}
 
Example #15
Source Project: apimanager-swagger-promote   Author: Axway-API-Management-Plus   File: AIPQuotaSerializerModifier.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public JsonSerializer<?> modifySerializer(SerializationConfig config, BeanDescription beanDesc, JsonSerializer<?> serializer) {
	if (beanDesc.getBeanClass() == APIQuota.class) {
		return new APIQuotaSerializer((JsonSerializer<Object>) serializer);
	}
	return super.modifySerializer(config, beanDesc, serializer);
}
 
Example #16
Source Project: botbuilder-java   Author: microsoft   File: FlatteningSerializer.java    License: MIT License 5 votes vote down vote up
/**
 * Gets a module wrapping this serializer as an adapter for the Jackson
 * ObjectMapper.
 *
 * @param mapper the object mapper for default serializations
 * @return a simple module to be plugged onto Jackson ObjectMapper.
 */
public static SimpleModule getModule(final ObjectMapper mapper) {
    SimpleModule module = new SimpleModule();
    module.setSerializerModifier(new BeanSerializerModifier() {
        @Override
        public JsonSerializer<?> modifySerializer(SerializationConfig config, BeanDescription beanDesc, JsonSerializer<?> serializer) {
            if (BeanSerializer.class.isAssignableFrom(serializer.getClass())) {
                return new FlatteningSerializer(beanDesc.getBeanClass(), serializer, mapper);
            }
            return serializer;
        }
    });
    return module;
}
 
Example #17
Source Project: ameba   Author: icode   File: FindSerializers.java    License: MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public JsonSerializer<?> findSerializer(SerializationConfig config, JavaType type, BeanDescription beanDesc) {

    if (jsonContext.isSupportedType(type.getRawClass())) {
        return createSerializer();
    }

    return null;
}
 
Example #18
Source Project: albedo   Author: somowhere   File: JacksonTest.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void testAddExtraField() throws Exception {
	ObjectMapper mapper = new ObjectMapper();

	mapper.registerModule(new SimpleModule() {

		public void setupModule(SetupContext context) {
			super.setupModule(context);

			context.addBeanSerializerModifier(new BeanSerializerModifier() {

				public JsonSerializer<?> modifySerializer(
					SerializationConfig config,
					BeanDescription beanDesc,
					JsonSerializer<?> serializer) {
					if (serializer instanceof BeanSerializerBase) {
						return new ExtraFieldSerializer(
							(BeanSerializerBase) serializer);
					}
					return serializer;

				}
			});
		}
	});

	mapper.writeValue(System.out, Lists.newArrayList(new MyClass1(), new MyClass2()));
	//prints {"classField":"classFieldValue","extraField":"extraFieldValue"}
}
 
Example #19
Source Project: spring-cloud-netflix   Author: spring-cloud   File: WebClientTransportClientFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Deprecated // reduce visibility in future release
public static BeanSerializerModifier createJsonSerializerModifier() {
	return new BeanSerializerModifier() {
		@Override
		public JsonSerializer<?> modifySerializer(SerializationConfig config,
				BeanDescription beanDesc, JsonSerializer<?> serializer) {
			if (beanDesc.getBeanClass().isAssignableFrom(InstanceInfo.class)) {
				return new InstanceInfoJsonBeanSerializer(
						(BeanSerializerBase) serializer, false);
			}
			return serializer;
		}
	};
}
 
Example #20
Source Project: datacollector   Author: streamsets   File: FlatRBeanSerializerModifier.java    License: Apache License 2.0 5 votes vote down vote up
public JsonSerializer<?> modifySerializer(
    SerializationConfig config,
    BeanDescription beanDesc,
    JsonSerializer<?> serializer
) {
  // Only use the serializer for any subclasses of RType
  if (RType.class.isAssignableFrom(beanDesc.getBeanClass()) && serializer instanceof BeanSerializerBase) {
    return new RBeanContextData((BeanSerializerBase) serializer);
  }
  return serializer;
}
 
Example #21
Source Project: servicecomb-java-chassis   Author: apache   File: AbstractArgumentsMapperCreator.java    License: Apache License 2.0 5 votes vote down vote up
public AbstractArgumentsMapperCreator(SerializationConfig serializationConfig,
    Map<Class<?>, ContextArgumentMapperFactory> contextFactorys, Class<?> providerClass,
    Method providerMethod, SwaggerOperation swaggerOperation) {
  this.serializationConfig = serializationConfig;
  this.contextFactorys = contextFactorys;
  this.providerClass = providerClass;
  this.providerMethod = providerMethod;
  this.swaggerOperation = swaggerOperation;

  this.swaggerParameters = new ArrayList<>(this.swaggerOperation.getOperation().getParameters());

  bodyParameter = findSwaggerBodyParameter();
  swaggerBodyProperties = SwaggerUtils.getBodyProperties(swaggerOperation.getSwagger(), bodyParameter);
  processedSwaggerParamters = new HashSet<>();
}
 
Example #22
Source Project: crnk-framework   Author: crnk-project   File: AnnotatedClassBuilder.java    License: Apache License 2.0 5 votes vote down vote up
private static AnnotatedClass buildOldAnnotatedClass(Method method, Class<?> declaringClass,
													 SerializationConfig serializationConfig)
		throws InvocationTargetException, IllegalAccessException {
	boolean useAnnotations = serializationConfig.isAnnotationProcessingEnabled();
	AnnotationIntrospector aintr = useAnnotations ? serializationConfig.getAnnotationIntrospector() : null;
	return (AnnotatedClass) method.invoke(null, declaringClass, aintr, serializationConfig);
}
 
Example #23
Source Project: crnk-framework   Author: crnk-project   File: JacksonResourceFieldInformationProvider.java    License: Apache License 2.0 5 votes vote down vote up
protected Optional<String> getName(Field field) {
	ObjectMapper objectMapper = context.getObjectMapper();
	SerializationConfig serializationConfig = objectMapper.getSerializationConfig();

	if (serializationConfig != null && serializationConfig.getPropertyNamingStrategy() != null) {
		AnnotationMap annotationMap = buildAnnotationMap(field.getDeclaredAnnotations());

		AnnotatedClass annotatedClass = AnnotatedClassBuilder.build(field.getDeclaringClass(), serializationConfig);
		AnnotatedField annotatedField = AnnotatedFieldBuilder.build(annotatedClass, field, annotationMap);
		return Optional.of(serializationConfig.getPropertyNamingStrategy().nameForField(serializationConfig, annotatedField, field.getName()));
	}
	return Optional.empty();
}
 
Example #24
Source Project: azure-libraries-for-java   Author: Azure   File: OdataTypeDiscriminatorTypeResolver.java    License: MIT License 5 votes vote down vote up
@Override
public TypeSerializer buildTypeSerializer(SerializationConfig config, JavaType baseType, Collection<NamedType> subtypes) {
    //Copied this code from parent class, StdTypeResolverBuilder with same method name
    TypeIdResolver idRes = this.idResolver(config, baseType, subtypes, true, false);
    // have to escape "." in the middle of the "odata.type" otherwise it will be serialized to "odata": { "type":"Value"} JSON
    String escapedString = this._typeProperty.replace(".", "\\.");
    return new AsPropertyTypeSerializer(idRes, (BeanProperty) null, escapedString);
}
 
Example #25
Source Project: spring-boot-admin   Author: codecentric   File: RegistrationBeanSerializerModifier.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public List<BeanPropertyWriter> changeProperties(SerializationConfig config, BeanDescription beanDesc,
		List<BeanPropertyWriter> beanProperties) {
	if (!Registration.class.isAssignableFrom(beanDesc.getBeanClass())) {
		return beanProperties;
	}

	beanProperties.stream().filter((beanProperty) -> "metadata".equals(beanProperty.getName()))
			.forEach((beanProperty) -> beanProperty.assignSerializer(metadataSerializer));
	return beanProperties;
}
 
Example #26
Source Project: quilt   Author: hyperledger   File: InterledgerSerializers.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public JsonSerializer<?> findSerializer(
    SerializationConfig config, JavaType type, BeanDescription beanDesc
) {
  final Class<?> raw = type.getRawClass();
  if (InterledgerAddress.class.isAssignableFrom(raw)) {
    return InterledgerAddressSerializer.INSTANCE;
  }
  if (InterledgerAddressPrefix.class.isAssignableFrom(raw)) {
    return new InterledgerAddressPrefixSerializer();
  }
  if (InterledgerCondition.class.isAssignableFrom(raw)) {
    return new ConditionSerializer(cryptoConditionEncoding);
  }
  if (InterledgerFulfillment.class.isAssignableFrom(raw)) {
    return new FulfillmentSerializer(cryptoConditionEncoding);
  }
  if (SharedSecret.class.isAssignableFrom(raw)) {
    return new SharedSecretSerializer();
  }
  if (LinkId.class.isAssignableFrom(raw)) {
    return new LinkIdSerializer();
  }
  if (LinkType.class.isAssignableFrom(raw)) {
    return new LinkTypeSerializer();
  }

  return null;
}
 
Example #27
Source Project: curiostack   Author: curioswitch   File: ProtobufModule.java    License: MIT License 5 votes vote down vote up
@Override
@Nullable
public JsonSerializer<?> findSerializer(
    SerializationConfig config, JavaType type, BeanDescription beanDesc) {
  if (Message.class.isAssignableFrom(type.getRawClass())) {
    return new MessageSerializer();
  }
  return null;
}
 
Example #28
Source Project: log4j2-elasticsearch   Author: rfoltyns   File: JacksonJsonLayout.java    License: Apache License 2.0 5 votes vote down vote up
protected ObjectWriter createConfiguredWriter(List<JacksonMixIn> mixins) {

            ObjectMapper objectMapper = createDefaultObjectMapper();
            objectMapper.registerModule(new ExtendedLog4j2JsonModule());

            if (useAfterburner) {
                // com.fasterxml.jackson.module:jackson-module-afterburner required here
                new JacksonAfterburnerModuleConfigurer().configure(objectMapper);
            }

            for (JacksonMixIn mixin : mixins) {
                objectMapper.addMixIn(mixin.getTargetClass(), mixin.getMixInClass());
            }

            ValueResolver valueResolver = createValueResolver();

            for (VirtualProperty property : virtualProperties) {
                if (!property.isDynamic()) {
                    property.setValue(valueResolver.resolve(property.getValue()));
                }
            }

            SerializationConfig customConfig = objectMapper.getSerializationConfig()
                    .with(new JacksonHandlerInstantiator(
                            virtualProperties,
                            valueResolver,
                            virtualPropertyFilters
                    ));

            objectMapper.setConfig(customConfig);

            return objectMapper.writer(new MinimalPrettyPrinter());

        }
 
Example #29
Source Project: log4j2-elasticsearch   Author: rfoltyns   File: VirtualPropertiesWriterTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void withConfigReturnsConfiguredWriter() {

    // given
    ObjectMapper objectMapper = new ObjectMapper();
    SerializationConfig config = objectMapper.getSerializationConfig();

    VirtualPropertiesWriter writer = spy(new VirtualPropertiesWriter(
            new VirtualProperty[0],
            mock(ValueResolver.class),
            new VirtualPropertyFilter[0]
    ));

    JavaType javaType = config.constructType(LogEvent.class);
    AnnotatedClass annotatedClass = createTestAnnotatedClass(config, javaType);

    SimpleBeanPropertyDefinition simpleBeanPropertyDefinition =
            getTestBeanPropertyDefinition(config, javaType, annotatedClass);

    VirtualPropertiesWriter result = writer.withConfig(
            config,
            annotatedClass,
            simpleBeanPropertyDefinition,
            config.constructType(VirtualProperty.class)
    );

    // then
    assertArrayEquals(writer.virtualProperties, result.virtualProperties);
    assertEquals(writer.valueResolver, result.valueResolver);
    assertEquals(writer.filters, result.filters);

}
 
Example #30
Source Project: log4j2-elasticsearch   Author: rfoltyns   File: VirtualPropertiesWriterTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void writerCreatedWithDeprecatedConstructorWritesGivenProperties() throws Exception {

    // given
    ObjectMapper objectMapper = new ObjectMapper();
    SerializationConfig config = objectMapper.getSerializationConfig();

    JavaType javaType = config.constructType(LogEvent.class);
    AnnotatedClass annotatedClass = createTestAnnotatedClass(config, javaType);

    SimpleBeanPropertyDefinition simpleBeanPropertyDefinition =
            getTestBeanPropertyDefinition(config, javaType, annotatedClass);

    String expectedName = UUID.randomUUID().toString();
    String expectedValue = UUID.randomUUID().toString();
    VirtualProperty virtualProperty = spy(createNonDynamicVirtualProperty(expectedName, expectedValue));

    ValueResolver valueResolver = createTestValueResolver(virtualProperty, expectedValue);

    VirtualPropertiesWriter writer = new VirtualPropertiesWriter(
            simpleBeanPropertyDefinition,
            new AnnotationCollector.OneAnnotation(
                    annotatedClass.getRawType(),
                    annotatedClass.getAnnotations().get(JsonAppend.class)
            ),
            javaType,
            new VirtualProperty[] { virtualProperty },
            valueResolver
    );

    JsonGenerator jsonGenerator = mock(JsonGenerator.class);

    // when
    writer.serializeAsField(new Object(), jsonGenerator, mock(SerializerProvider.class));

    // then
    verify(jsonGenerator).writeFieldName(eq(expectedName));
    verify(jsonGenerator).writeString(eq(expectedValue));

}