/** * Method that can be used to prune unwanted properties, during * construction of serializers and deserializers. * Use with utmost care, if at all... * * @since 2.1 */ public boolean removeProperty(String propName) { Iterator<BeanPropertyDefinition> it = _properties().iterator(); while (it.hasNext()) { BeanPropertyDefinition prop = it.next(); if (prop.getName().equals(propName)) { it.remove(); return true; } } return false; }
@Deprecated // since 2.9 @Override public Map<String,AnnotatedMember> findBackReferenceProperties() { List<BeanPropertyDefinition> props = findBackReferences(); if (props == null) { return null; } Map<String,AnnotatedMember> result = new HashMap<>(); for (BeanPropertyDefinition prop : props) { result.put(prop.getName(), prop.getMutator()); } return result; }
AnnotatedField f = property.getField(); if (f != null) { String name = property.getName(); if (ignoredProperties != null) { if (ignoredProperties.contains(name)) {
String name = property.getName(); if (ignored.contains(name)) { // explicit ignoral using @JsonIgnoreProperties needs to block entries continue;
private boolean _checkIfCreatorPropertyBased(AnnotationIntrospector intr, AnnotatedWithParams creator, BeanPropertyDefinition propDef) { // If explicit name, or inject id, property-based if (((propDef != null) && propDef.isExplicitlyNamed()) || (intr.findInjectableValue(creator.getParameter(0)) != null)) { return true; } if (propDef != null) { // One more thing: if implicit name matches property with a getter // or field, we'll consider it property-based as well String implName = propDef.getName(); if (implName != null && !implName.isEmpty()) { if (propDef.couldSerialize()) { return true; } } } // in absence of everything else, default to delegating return false; }
/** * Helper method called to indicate problem in POJO (serialization) definitions or settings * regarding specific property (of a type), unrelated to actual JSON content to map. * Default behavior is to construct and throw a {@link JsonMappingException}. * * @since 2.9 */ public <T> T reportBadPropertyDefinition(BeanDescription bean, BeanPropertyDefinition prop, String message, Object... msgArgs) throws JsonMappingException { message = _format(message, msgArgs); String propName = "N/A"; if (prop != null) { propName = _quotedString(prop.getName()); } String beanDesc = "N/A"; if (bean != null) { beanDesc = ClassUtil.nameOf(bean.getBeanClass()); } message = String.format("Invalid definition for property %s (of type %s): %s", propName, beanDesc, message); throw InvalidDefinitionException.from(getGenerator(), message, bean, prop); }
final String propName = property.getName();
_contextAnnotations = contextAnnotations; _name = new SerializedString(propDef.getName()); _wrapperName = propDef.getWrapperName();
final String name = def.getName(); if (name != null && name.equals(propertyName)) { final AnnotatedMember propMember = def.getPrimaryMember();
/** * Mostly for kotlin null safe operator and immutable properties. * * @param type Target type. * @param model Model. * @return Input model. */ private Model doModel(Type type, Model model) { Map<String, Property> properties = model.getProperties(); if (properties != null) { BeanDescription desc = Json.mapper().getSerializationConfig() .introspect(Json.mapper().constructType(type)); for (BeanPropertyDefinition beanProperty : desc.findProperties()) { Property property = properties.get(beanProperty.getName()); if (property != null) { property.setRequired(beanProperty.isRequired()); } } } return model; }
/** * @param property must not be {@literal null} * @return the mapped name for the {@link PersistentProperty} */ public String getMappedName(PersistentProperty<?> property) { Assert.notNull(property, "PersistentProperty must not be null!"); return propertyToFieldName.get(property).getName(); }
/** * Returns the {@link PersistentProperty} for the property with the given final name (the name that it will be * rendered under eventually). * * @param finalName the output name the property will be rendered under. * @param entity the {@link PersistentEntity} to find the property on. * @param description the Jackson {@link BeanDescription}. * @return */ private Optional<? extends PersistentProperty<?>> findProperty(String finalName, PersistentEntity<?, ? extends PersistentProperty<?>> entity, BeanDescription description) { return description.findProperties().stream()// .filter(it -> it.getName().equals(finalName))// .findFirst().map(it -> entity.getPersistentProperty(it.getInternalName())); } }
valueToSuppress = am.getValue(defaultBean); } catch (Exception e) { _throwWrapped(e, propDef.getName(), defaultBean);
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); } }
private Map<String, List<PersistentProperty<?>>> findUnwrappedPropertyPaths(Class<?> type, NameTransformer nameTransformer, boolean considerRegularProperties) { return persistentEntities.getPersistentEntity(type).map(entity -> { Map<String, List<PersistentProperty<?>>> mapping = new HashMap<String, List<PersistentProperty<?>>>(); for (BeanPropertyDefinition property : getMappedProperties(entity)) { Optionals.ifAllPresent(Optional.ofNullable(entity.getPersistentProperty(property.getInternalName())), // findAnnotatedMember(property), // (prop, member) -> { if (isJsonUnwrapped(member)) { mapping.putAll(findUnwrappedPropertyPaths(nameTransformer, member, prop)); } else if (considerRegularProperties) { mapping.put(nameTransformer.transform(property.getName()), Collections.<PersistentProperty<?>> singletonList(prop)); } }); } return mapping; }).orElse(Collections.emptyMap()); }
private List<Descriptor> createJacksonDescriptor(String name, Class<?> type) { List<Descriptor> descriptors = new ArrayList<Descriptor>(); for (BeanPropertyDefinition definition : new JacksonMetadata(mapper, type)) { AnnotatedMethod getter = definition.getGetter(); Description description = getter.getAnnotation(Description.class); ResourceDescription fallback = SimpleResourceDescription .defaultFor(String.format("%s.%s", name, definition.getName())); ResourceDescription resourceDescription = description == null ? null : new AnnotationBasedResourceDescription(description, fallback); descriptors.add(// descriptor().// name(definition.getName()).// type(Type.SEMANTIC).// doc(getDocFor(resourceDescription)).// build()); } return descriptors; }
private JsonSchemaProperty getSchemaProperty(BeanPropertyDefinition definition, TypeInformation<?> type, ResourceDescription description, MessageResolver resolver) { String name = definition.getName(); String title = resolver.resolveWithDefault(new ResolvableProperty(definition)); String resolvedDescription = resolver.resolve(description); boolean required = definition.isRequired(); Class<?> rawType = type.getType(); if (!rawType.isEnum()) { return new JsonSchemaProperty(name, title, resolvedDescription, required).with(type); } String message = resolver.resolve(new DefaultMessageSourceResolvable(description.getMessage())); return new EnumProperty(name, title, rawType, description.getDefaultMessage().equals(resolvedDescription) ? message : resolvedDescription, required); } }
@Override public void doWithPersistentProperty(PersistentProperty<?> property) { BeanPropertyDefinition propertyDefinition = jackson.getDefinitionFor(property); ResourceMapping propertyMapping = metadata.getMappingFor(property); if (propertyDefinition != null) { if (property.isIdProperty() && !configuration.isIdExposedFor(property.getOwner().getType())) { return; } propertyDescriptors.add(// descriptor(). // type(Type.SEMANTIC).// name(propertyDefinition.getName()).// doc(getDocFor(propertyMapping.getDescription(), property)).// build()); } } });