@Override public ValueInstantiator findValueInstantiator(DeserializationConfig config, BeanDescription beanDesc, ValueInstantiator defaultInstantiator) { ValueInstantiator inst = _classMappings.get(new ClassKey(beanDesc.getBeanClass())); return (inst == null) ? defaultInstantiator : inst; } }
@Override public JsonSerializer<?> modifySerializer(SerializationConfig config, BeanDescription beanDesc, JsonSerializer<?> serializer) { if (beanDesc.getBeanClass().isAssignableFrom(Applications.class)) { return new ApplicationsXmlBeanSerializer((BeanSerializerBase) serializer, keyFormatter); } if (beanDesc.getBeanClass().isAssignableFrom(InstanceInfo.class)) { return new InstanceInfoXmlBeanSerializer((BeanSerializerBase) serializer); } return serializer; } };
@Override public JsonSerializer<?> modifySerializer(SerializationConfig config, BeanDescription beanDesc, JsonSerializer<?> serializer) { if (beanDesc.getBeanClass().isAssignableFrom(Applications.class)) { return new ApplicationsJsonBeanSerializer((BeanSerializerBase) serializer, keyFormatter); } if (beanDesc.getBeanClass().isAssignableFrom(InstanceInfo.class)) { return new InstanceInfoJsonBeanSerializer((BeanSerializerBase) serializer, compactMode); } return serializer; } };
@Override public JsonDeserializer<?> modifyDeserializer(DeserializationConfig config, BeanDescription beanDesc, JsonDeserializer<?> deserializer) { if (Response.class.isAssignableFrom(beanDesc.getBeanClass())) { return new RawResponseDeserializer(deserializer); } return deserializer; } });
@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; } }
/** * Helper method called to indicate problem in POJO (serialization) definitions or settings * regarding specific Java type, unrelated to actual JSON content to map. * Default behavior is to construct and throw a {@link JsonMappingException}. * * @since 2.9 */ public <T> T reportBadTypeDefinition(BeanDescription bean, String msg, Object... msgArgs) throws JsonMappingException { msg = _format(msg, msgArgs); String beanDesc = ClassUtil.nameOf(bean.getBeanClass()); msg = String.format("Invalid type definition for type %s: %s", beanDesc, msg); throw InvalidDefinitionException.from(_parser, msg, bean, null); }
public void addPropertyCreator(AnnotatedWithParams creator, boolean explicit, SettableBeanProperty[] properties) { if (verifyNonDup(creator, C_PROPS, explicit)) { // Better ensure we have no duplicate names either... if (properties.length > 1) { HashMap<String, Integer> names = new HashMap<String, Integer>(); for (int i = 0, len = properties.length; i < len; ++i) { String name = properties[i].getName(); // Need to consider Injectables, which may not have // a name at all, and need to be skipped if (name.isEmpty() && (properties[i].getInjectableValueId() != null)) { continue; } Integer old = names.put(name, Integer.valueOf(i)); if (old != null) { throw new IllegalArgumentException(String.format( "Duplicate creator property \"%s\" (index %s vs %d) for type %s ", name, old, i, ClassUtil.nameOf(_beanDesc.getBeanClass()))); } } } _propertyBasedArgs = properties; } }
private ValueInstantiator _findStdValueInstantiator(DeserializationConfig config, BeanDescription beanDesc) throws JsonMappingException { Class<?> raw = beanDesc.getBeanClass(); if (raw == JsonLocation.class) { return new JsonLocationInstantiator(); } // [databind#1868]: empty List/Set/Map if (Collection.class.isAssignableFrom(raw)) { if (Collections.EMPTY_SET.getClass() == raw) { return new ConstantValueInstantiator(Collections.EMPTY_SET); } if (Collections.EMPTY_LIST.getClass() == raw) { return new ConstantValueInstantiator(Collections.EMPTY_LIST); } } else if (Map.class.isAssignableFrom(raw)) { if (Collections.EMPTY_MAP.getClass() == raw) { return new ConstantValueInstantiator(Collections.EMPTY_MAP); } } return null; }
/** * Overridable method that can filter out properties. Default implementation * checks annotations class may have. */ protected List<BeanPropertyWriter> filterBeanProperties(SerializationConfig config, BeanDescription beanDesc, List<BeanPropertyWriter> props) { // 01-May-2016, tatu: Which base type to use here gets tricky, since // it may often make most sense to use general type for overrides, // but what we have here may be more specific impl type. But for now // just use it as is. JsonIgnoreProperties.Value ignorals = config.getDefaultPropertyIgnorals(beanDesc.getBeanClass(), beanDesc.getClassInfo()); if (ignorals != null) { Set<String> ignored = ignorals.findIgnoredForSerialization(); if (!ignored.isEmpty()) { Iterator<BeanPropertyWriter> it = props.iterator(); while (it.hasNext()) { if (ignored.contains(it.next().getName())) { it.remove(); } } } } return props; }
/** * 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 msg, Object... msgArgs) throws JsonMappingException { msg = _format(msg, msgArgs); String propName = ClassUtil.nameOf(prop); String beanDesc = ClassUtil.nameOf(bean.getBeanClass()); msg = String.format("Invalid definition for property %s (of type %s): %s", propName, beanDesc, msg); throw InvalidDefinitionException.from(_parser, msg, bean, prop); }
/** * Helper method called to indicate problem in POJO (serialization) definitions or settings * regarding specific Java type, unrelated to actual JSON content to map. * Default behavior is to construct and throw a {@link JsonMappingException}. * * @since 2.9 */ public <T> T reportBadTypeDefinition(BeanDescription bean, String msg, Object... msgArgs) throws JsonMappingException { String beanDesc = "N/A"; if (bean != null) { beanDesc = ClassUtil.nameOf(bean.getBeanClass()); } msg = String.format("Invalid type definition for type %s: %s", beanDesc, _format(msg, msgArgs)); throw InvalidDefinitionException.from(getGenerator(), msg, bean, null); }
@Override public List<BeanPropertyWriter> changeProperties(SerializationConfig config, BeanDescription description, List<BeanPropertyWriter> properties) { Class<?> type = description.getBeanClass(); ElasticsearchPersistentEntity<?> entity = context.getPersistentEntity(type); if (entity == null) { return super.changeProperties(config, description, properties); } List<BeanPropertyWriter> result = new ArrayList<>(properties.size()); for (BeanPropertyWriter beanPropertyWriter : properties) { ElasticsearchPersistentProperty property = entity.getPersistentProperty(beanPropertyWriter.getName()); if (property != null && property.isWritable()) { result.add(beanPropertyWriter); } } return result; } }
/** * 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); }
_context.reportBadDefinition(_beanDesc.getType(), String.format("Builder class %s does not have build method (name: '%s')", _beanDesc.getBeanClass().getName(), expBuildMethodName));
throw new IllegalArgumentException("Invalid Object Id definition for "+beanDesc.getBeanClass().getName() +": cannot find property with name '"+propName+"'");
public PropertyBuilder(SerializationConfig config, BeanDescription beanDesc) { _config = config; _beanDesc = beanDesc; // 08-Sep-2016, tatu: This gets tricky, with 3 levels of definitions: // (a) global default inclusion // (b) per-type default inclusion (from annotation or config overrides; // config override having precedence) // (c) per-property override (from annotation on specific property or // config overrides per type of property; // annotation having precedence) // // and not only requiring merging, but also considering special handling // for NON_DEFAULT in case of (b) (vs (a) or (c)) JsonInclude.Value inclPerType = JsonInclude.Value.merge( beanDesc.findPropertyInclusion(JsonInclude.Value.empty()), config.getDefaultPropertyInclusion(beanDesc.getBeanClass(), JsonInclude.Value.empty())); _defaultInclusion = JsonInclude.Value.merge(config.getDefaultPropertyInclusion(), inclPerType); _useRealPropertyDefaults = inclPerType.getValueInclusion() == JsonInclude.Include.NON_DEFAULT; _annotationIntrospector = _config.getAnnotationIntrospector(); }
if (idProp == null) { throw new IllegalArgumentException("Invalid Object Id definition for " +beanDesc.getBeanClass().getName()+": cannot find property with name '"+propName+"'");
VisibilityChecker<?> vchecker = config.getDefaultVisibilityChecker(beanDesc.getBeanClass(), beanDesc.getClassInfo());
if (beanDesc.getBeanClass() == Object.class) { return prov.getUnknownTypeSerializer(Object.class);
ser = prov.getUnknownTypeSerializer(beanDesc.getBeanClass());