com.fasterxml.jackson.databind.util.SimpleBeanPropertyDefinition Java Examples
The following examples show how to use
com.fasterxml.jackson.databind.util.SimpleBeanPropertyDefinition.
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: TestAccessorGeneration.java From jackson-modules-base with Apache License 2.0 | 6 votes |
public void testSingleIntAccessorGeneration() throws Exception { Method method = Bean1.class.getDeclaredMethod("getX"); AnnotatedMethod annMethod = new AnnotatedMethod(null, method, null, null); PropertyAccessorCollector coll = new PropertyAccessorCollector(Bean1.class); BeanPropertyWriter bpw = new BeanPropertyWriter(SimpleBeanPropertyDefinition .construct(MAPPER_CONFIG, annMethod, new PropertyName("x")), annMethod, null, null, null, null, null, false, null, null); coll.addIntGetter(bpw); BeanPropertyAccessor acc = coll.findAccessor(null); Bean1 bean = new Bean1(); int value = acc.intGetter(bean, 0); assertEquals(bean.getX(), value); }
Example #2
Source File: VirtualPropertiesWriterTest.java From log4j2-elasticsearch with Apache License 2.0 | 5 votes |
@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 #3
Source File: VirtualPropertiesWriterTest.java From log4j2-elasticsearch with Apache License 2.0 | 5 votes |
@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)); }
Example #4
Source File: VirtualPropertiesWriterTest.java From log4j2-elasticsearch with Apache License 2.0 | 5 votes |
private SimpleBeanPropertyDefinition getTestBeanPropertyDefinition(SerializationConfig config, JavaType javaType, AnnotatedClass annotatedClass) { return SimpleBeanPropertyDefinition.construct( config, new VirtualAnnotatedMember( annotatedClass, LogEvent.class, "virtualProperties", javaType ) ); }
Example #5
Source File: TestAccessorGeneration.java From jackson-modules-base with Apache License 2.0 | 5 votes |
public void testDualIntAccessorGeneration() throws Exception { PropertyAccessorCollector coll = new PropertyAccessorCollector(Bean3.class); String[] methodNames = new String[] { "getX", "getY", "get3" }; /* public BeanPropertyWriter(BeanPropertyDefinition propDef, AnnotatedMember member, Annotations contextAnnotations, JavaType declaredType, JsonSerializer<Object> ser, TypeSerializer typeSer, JavaType serType, boolean suppressNulls, Object suppressableValue) */ for (String methodName : methodNames) { Method method = Bean3.class.getDeclaredMethod(methodName); AnnotatedMethod annMethod = new AnnotatedMethod(null, method, null, null); // should we translate from method name to property name? coll.addIntGetter(new BeanPropertyWriter(SimpleBeanPropertyDefinition .construct(MAPPER_CONFIG, annMethod, new PropertyName(methodName)), annMethod, null, null, null, null, null, false, null, null)); } BeanPropertyAccessor acc = coll.findAccessor(null); Bean3 bean = new Bean3(); assertEquals(bean.getX(), acc.intGetter(bean, 0)); assertEquals(bean.getY(), acc.intGetter(bean, 1)); assertEquals(bean.get3(), acc.intGetter(bean, 2)); }
Example #6
Source File: TestAccessorGeneration.java From jackson-modules-base with Apache License 2.0 | 5 votes |
public void testLotsaIntAccessorGeneration() throws Exception { PropertyAccessorCollector coll = new PropertyAccessorCollector(BeanN.class); String[] methodNames = new String[] { "getX", "getY", "get3", "get4", "get5", "get6", "get7" }; for (String methodName : methodNames) { Method method = BeanN.class.getDeclaredMethod(methodName); AnnotatedMethod annMethod = new AnnotatedMethod(null, method, null, null); coll.addIntGetter(new BeanPropertyWriter(SimpleBeanPropertyDefinition.construct( MAPPER_CONFIG, annMethod, new PropertyName(methodName)), annMethod, null, null, null, null, null, false, null, null)); } BeanPropertyAccessor acc = coll.findAccessor(null); BeanN bean = new BeanN(); assertEquals(bean.getX(), acc.intGetter(bean, 0)); assertEquals(bean.getY(), acc.intGetter(bean, 1)); assertEquals(bean.get3(), acc.intGetter(bean, 2)); assertEquals(bean.get4(), acc.intGetter(bean, 3)); assertEquals(bean.get5(), acc.intGetter(bean, 4)); assertEquals(bean.get6(), acc.intGetter(bean, 5)); assertEquals(bean.get7(), acc.intGetter(bean, 6)); }