/** * Method for constructing dummy bean deserializer; one that * never outputs any properties */ public static BeanSerializer createDummy(Class<?> forType) { return new BeanSerializer(forType, NO_PROPS, null, null, null); }
/** * Factory method for constructing an "empty" serializer; one that * outputs no properties (but handles JSON objects properly, including * type information) */ public BeanSerializer createDummy() { return BeanSerializer.createDummy(_beanDesc.getBeanClass()); } }
@Override public String toString() { return "BeanSerializer for "+handledType().getName(); } }
/** * Main serialization method that will delegate actual output to * configured * {@link BeanPropertyWriter} instances. */ @Override public final void serialize(Object bean, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonGenerationException { jgen.writeStartObject(); if (_propertyFilterId != null) { serializeFieldsFiltered(bean, jgen, provider); } else { serializeFields(bean, jgen, provider); } jgen.writeEndObject(); }
protected JsonSerializer<Object> constructBeanSerializer(SerializationConfig config, BasicBeanDescription beanDesc) { // First: any detectable (auto-detect, annotations) properties to serialize? List<BeanPropertyWriter> props = findBeanProperties(config, beanDesc); if (props == null || props.size() == 0) { // No properties, no serializer /* 27-Nov-2009, tatu: Except that as per [JACKSON-201], we are * ok with that as long as it has a recognized class annotation * (which may come from a mix-in too) */ if (beanDesc.hasKnownClassAnnotations()) { return BeanSerializer.createDummy(beanDesc.classDescribed()); } return null; } // Any properties to suppress? props = filterBeanProperties(config, beanDesc, props); // Do they need to be sorted in some special way? props = sortBeanProperties(config, beanDesc, props); BeanSerializer ser = new BeanSerializer(beanDesc.classDescribed(), props); // One more thing: need to gather view information, if any: ser = processViews(config, beanDesc, ser, props); return ser; }
props = _props; final BeanPropertyFilter filter = findFilter(provider); int i = 0; try { wrapAndThrow(provider, e, bean, name); } catch (StackOverflowError e) { JsonMappingException mapE = new JsonMappingException("Infinite recursion (StackOverflowError)");
public JsonNode getSchema(SerializerProvider provider, Type typeHint) throws JsonMappingException ObjectNode o = createSchemaNode("object", true);
wrapAndThrow(provider, e, bean, name); } catch (StackOverflowError e) {
/** * Main serialization method that will delegate actual output to * configured * {@link BeanPropertyWriter} instances. */ @Override public final void serialize(Object bean, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonGenerationException { jgen.writeStartObject(); if (_propertyFilterId != null) { serializeFieldsFiltered(bean, jgen, provider); } else { serializeFields(bean, jgen, provider); } jgen.writeEndObject(); }
@Override public JsonNode getSchema(SerializerProvider provider, Type typeHint) throws JsonMappingException { ObjectNode o = createSchemaNode("object", true); //todo: should the classname go in the title? //o.put("title", _className); ObjectNode propertiesNode = o.objectNode(); for (int i = 0; i < _props.length; i++) { BeanPropertyWriter prop = _props[i]; JavaType propType = prop.getSerializationType(); // 03-Dec-2010, tatu: SchemaAware REALLY should use JavaType, but alas it doesn't... Type hint = (propType == null) ? prop.getGenericPropertyType() : propType.getRawClass(); // Maybe it already has annotated/statically configured serializer? JsonSerializer<Object> ser = prop.getSerializer(); if (ser == null) { // nope Class<?> serType = prop.getRawSerializationType(); if (serType == null) { serType = prop.getPropertyType(); } ser = provider.findValueSerializer(serType, prop); } JsonNode schemaNode = (ser instanceof SchemaAware) ? ((SchemaAware) ser).getSchema(provider, hint) : JsonSchema.getDefaultSchemaNode(); propertiesNode.put(prop.getName(), schemaNode); } o.put("properties", propertiesNode); return o; }
wrapAndThrow(e, bean, props[i].getName()); } catch (StackOverflowError e) {
/** * Method called to create {@link BeanSerializer} instance with * all accumulated information. Will construct a serializer if we * have enough information, or return null if not. */ public JsonSerializer<?> build() { BeanPropertyWriter[] properties; // No properties or any getter? No real serializer; caller gets to handle if (_properties == null || _properties.isEmpty()) { if (_anyGetter == null) { return null; } properties = NO_PROPERTIES; } else { properties = _properties.toArray(new BeanPropertyWriter[_properties.size()]); } return new BeanSerializer(_beanDesc.getType(), properties, _filteredProperties, _anyGetter, _filterId); }
@Override public void serializeWithType(Object bean, JsonGenerator jgen, SerializerProvider provider, TypeSerializer typeSer) throws IOException, JsonGenerationException { typeSer.writeTypePrefixForObject(bean, jgen); if (_propertyFilterId != null) { serializeFieldsFiltered(bean, jgen, provider); } else { serializeFields(bean, jgen, provider); } typeSer.writeTypeSuffixForObject(bean, jgen); }
/** * Factory method for constructing an "empty" serializer; one that * outputs no properties (but handles JSON objects properly, including * type information) */ public BeanSerializer createDummy() { return BeanSerializer.createDummy(_beanDesc.getBeanClass()); } }
@Override public String toString() { return "BeanSerializer for "+handledType().getName(); } }
/** * Method for constructing dummy bean deserializer; one that * never outputs any properties */ public static BeanSerializer createDummy(Class<?> forType) { return new BeanSerializer(forType, NO_PROPS, null, null, null); }
/** * Main serialization method that will delegate actual output to * configured * {@link BeanPropertyWriter} instances. */ @Override public final void serialize(Object bean, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonGenerationException { jgen.writeStartObject(); if (_propertyFilterId != null) { serializeFieldsFiltered(bean, jgen, provider); } else { serializeFields(bean, jgen, provider); } jgen.writeEndObject(); }
/** * Factory method for constructing an "empty" serializer; one that * outputs no properties (but handles JSON objects properly, including * type information) */ public BeanSerializer createDummy() { return BeanSerializer.createDummy(_beanDesc.getBeanClass()); } }
@Override public String toString() { return "BeanSerializer for "+handledType().getName(); } }
/** * Method called to create {@link BeanSerializer} instance with * all accumulated information. Will construct a serializer if we * have enough information, or return null if not. */ public JsonSerializer<?> build() { BeanPropertyWriter[] properties; // No properties or any getter? No real serializer; caller gets to handle if (_properties == null || _properties.isEmpty()) { if (_anyGetter == null) { return null; } properties = NO_PROPERTIES; } else { properties = _properties.toArray(new BeanPropertyWriter[_properties.size()]); } return new BeanSerializer(_beanDesc.getType(), properties, _filteredProperties, _anyGetter, _filterId); }