use of com.fasterxml.jackson.databind.BeanDescription in project java-chassis by ServiceComb.
the class JacksonPropertyNodeNameProvider method getJavaBeanPropertyName.
private String getJavaBeanPropertyName(JavaBeanProperty property) {
ObjectMapper objectMapper = DatabindCodec.mapper();
JavaType type = objectMapper.constructType(property.getDeclaringClass());
BeanDescription desc = objectMapper.getSerializationConfig().introspect(type);
return desc.findProperties().stream().filter(prop -> prop.getInternalName().equals(property.getName())).map(BeanPropertyDefinition::getName).findFirst().orElse(property.getName());
}
use of com.fasterxml.jackson.databind.BeanDescription in project java-chassis by ServiceComb.
the class ConfigObjectFactory method createProperties.
public List<ConfigObjectProperty> createProperties(Object instance, String prefix, Map<String, Object> parameters) {
List<ConfigObjectProperty> properties = new ArrayList<>();
JavaType javaType = TypeFactory.defaultInstance().constructType(instance.getClass());
BeanDescription beanDescription = JsonUtils.OBJ_MAPPER.getSerializationConfig().introspect(javaType);
for (BeanPropertyDefinition propertyDefinition : beanDescription.findProperties()) {
if (propertyDefinition.getField() == null) {
continue;
}
if (propertyDefinition.getSetter() == null && !propertyDefinition.getField().isPublic()) {
continue;
}
Setter<Object, Object> setter = createObjectSetter(propertyDefinition);
PriorityProperty<?> priorityProperty = createPriorityProperty(propertyDefinition.getField().getAnnotated(), prefix, parameters);
setter.set(instance, priorityProperty.getValue());
properties.add(new ConfigObjectProperty(setter, priorityProperty));
}
return properties;
}
use of com.fasterxml.jackson.databind.BeanDescription in project java-chassis by ServiceComb.
the class BeanDescriptor method init.
public void init(SerializationConfig serializationConfig, JavaType javaType) {
this.javaType = javaType;
BeanDescription beanDescription = serializationConfig.introspect(javaType);
for (BeanPropertyDefinition propertyDefinition : beanDescription.findProperties()) {
PropertyDescriptor propertyDescriptor = new PropertyDescriptor();
propertyDescriptor.setName(propertyDefinition.getName());
propertyDescriptor.setJavaType(propertyDefinition.getPrimaryType());
try {
propertyDescriptor.setGetter(initGetter(propertyDefinition));
} catch (Throwable e) {
LOGGER.error("failed to init getter for field {}:{}", javaType.getRawClass().getName(), propertyDefinition.getName(), e);
}
try {
propertyDescriptor.setSetter(initSetter(propertyDefinition));
} catch (Throwable e) {
LOGGER.error("failed to init setter for field {}:{}", javaType.getRawClass().getName(), propertyDefinition.getName(), e);
}
propertyDescriptors.put(propertyDefinition.getName(), propertyDescriptor);
}
}
use of com.fasterxml.jackson.databind.BeanDescription in project java-chassis by ServiceComb.
the class AbstractOperationGenerator method extractAggregatedParameterGenerators.
protected void extractAggregatedParameterGenerators(Map<String, List<Annotation>> methodAnnotationMap, java.lang.reflect.Parameter methodParameter) {
JavaType javaType = TypeFactory.defaultInstance().constructType(methodParameter.getParameterizedType());
BeanDescription beanDescription = Json.mapper().getSerializationConfig().introspect(javaType);
for (BeanPropertyDefinition propertyDefinition : beanDescription.findProperties()) {
if (!propertyDefinition.couldSerialize()) {
continue;
}
Annotation[] annotations = collectAnnotations(propertyDefinition);
ParameterGenerator propertyParameterGenerator = new ParameterGenerator(method, methodAnnotationMap, propertyDefinition.getName(), annotations, propertyDefinition.getPrimaryType());
parameterGenerators.add(propertyParameterGenerator);
}
}
use of com.fasterxml.jackson.databind.BeanDescription in project snow-owl by b2ihealthcare.
the class ExtensionSerializer method serializeFields.
private void serializeFields(@SuppressWarnings("rawtypes") Extension bean, JsonGenerator gen, SerializerProvider provider) throws IOException {
JavaType javaType = provider.constructType(Extension.class);
BeanDescription beanDesc = provider.getConfig().introspect(javaType);
JsonSerializer<Object> serializer = BeanSerializerFactory.instance.findBeanOrAddOnSerializer(provider, javaType, beanDesc, false);
serializer.unwrappingSerializer(null).serialize(bean, gen, provider);
}
Aggregations