Categories:
Audio (13)
Biotech (29)
Bytecode (36)
Database (77)
Framework (7)
Game (7)
General (507)
Graphics (53)
I/O (35)
IDE (2)
JAR Tools (101)
JavaBeans (21)
JDBC (121)
JDK (426)
JSP (20)
Logging (108)
Mail (58)
Messaging (8)
Network (84)
PDF (97)
Report (7)
Scripting (84)
Security (32)
Server (121)
Servlet (26)
SOAP (24)
Testing (54)
Web (15)
XML (309)
Collections:
Other Resources:
Jackson Data Binding Source Code
Jackson is "the Java JSON library" or "the best JSON parser for Java". Or simply as "JSON for Java".
Jackson Databind Source Code files are provided in the source packge (jackson-databind-2.14.0-sources.jar). You can download it at Jackson Maven Website.
You can also browse Jackson Databind Source Code below:
✍: FYIcenter.com
⏎ com/fasterxml/jackson/databind/ser/impl/UnwrappingBeanPropertyWriter.java
package com.fasterxml.jackson.databind.ser.impl; import java.util.Iterator; import java.util.Map.Entry; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.io.SerializedString; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper; import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonObjectFormatVisitor; import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.ser.BeanPropertyWriter; import com.fasterxml.jackson.databind.util.NameTransformer; /** * Variant of {@link BeanPropertyWriter} which will handle unwrapping * of JSON Object (including of properties of Object within surrounding * JSON object, and not as sub-object). */ public class UnwrappingBeanPropertyWriter extends BeanPropertyWriter implements java.io.Serializable { private static final long serialVersionUID = 1L; /** * Transformer used to add prefix and/or suffix for properties * of unwrapped POJO. */ protected final NameTransformer _nameTransformer; /* /********************************************************** /* Life-cycle /********************************************************** */ public UnwrappingBeanPropertyWriter(BeanPropertyWriter base, NameTransformer unwrapper) { super(base); _nameTransformer = unwrapper; } protected UnwrappingBeanPropertyWriter(UnwrappingBeanPropertyWriter base, NameTransformer transformer, SerializedString name) { super(base, name); _nameTransformer = transformer; } @Override public UnwrappingBeanPropertyWriter rename(NameTransformer transformer) { String oldName = _name.getValue(); String newName = transformer.transform(oldName); // important: combine transformers: transformer = NameTransformer.chainedTransformer(transformer, _nameTransformer); return _new(transformer, new SerializedString(newName)); } /** * Overridable factory method used by sub-classes * * @since 2.6.0 */ protected UnwrappingBeanPropertyWriter _new(NameTransformer transformer, SerializedString newName) { return new UnwrappingBeanPropertyWriter(this, transformer, newName); } /* /********************************************************** /* Overrides, public methods /********************************************************** */ @Override public boolean isUnwrapping() { return true; } @Override public void serializeAsField(Object bean, JsonGenerator gen, SerializerProvider prov) throws Exception { final Object value = get(bean); if (value == null) { // Hmmh. I assume we MUST pretty much suppress nulls, since we // can't really unwrap them... return; } JsonSerializer<Object> ser = _serializer; if (ser == null) { Class<?> cls = value.getClass(); PropertySerializerMap map = _dynamicSerializers; ser = map.serializerFor(cls); if (ser == null) { ser = _findAndAddDynamic(map, cls, prov); } } if (_suppressableValue != null) { if (MARKER_FOR_EMPTY == _suppressableValue) { if (ser.isEmpty(prov, value)) { return; } } else if (_suppressableValue.equals(value)) { return; } } // For non-nulls, first: simple check for direct cycles if (value == bean) { if (_handleSelfReference(bean, gen, prov, ser)) { return; } } // note: must verify we are using unwrapping serializer; if not, will write field name if (!ser.isUnwrappingSerializer()) { gen.writeFieldName(_name); } if (_typeSerializer == null) { ser.serialize(value, gen, prov); } else { ser.serializeWithType(value, gen, prov, _typeSerializer); } } // need to override as we must get unwrapping instance... @Override public void assignSerializer(JsonSerializer<Object> ser) { if (ser != null) { NameTransformer t = _nameTransformer; if (ser.isUnwrappingSerializer() // as per [databind#2060], need to also check this, in case someone writes // custom implementation that does not extend standard implementation: && (ser instanceof UnwrappingBeanSerializer)) { t = NameTransformer.chainedTransformer(t, ((UnwrappingBeanSerializer) ser)._nameTransformer); } ser = ser.unwrappingSerializer(t); } super.assignSerializer(ser); } /* /********************************************************** /* Overrides: schema generation /********************************************************** */ @Override public void depositSchemaProperty(final JsonObjectFormatVisitor visitor, SerializerProvider provider) throws JsonMappingException { JsonSerializer<Object> ser = provider .findValueSerializer(this.getType(), this) .unwrappingSerializer(_nameTransformer); if (ser.isUnwrappingSerializer()) { ser.acceptJsonFormatVisitor(new JsonFormatVisitorWrapper.Base(provider) { // an unwrapping serializer will always expect ObjectFormat, // hence, the other cases do not have to be implemented @Override public JsonObjectFormatVisitor expectObjectFormat(JavaType type) throws JsonMappingException { return visitor; } }, this.getType()); } else { super.depositSchemaProperty(visitor, provider); } } // Override needed to support legacy JSON Schema generator @Override protected void _depositSchemaProperty(ObjectNode propertiesNode, JsonNode schemaNode) { JsonNode props = schemaNode.get("properties"); if (props != null) { Iterator<Entry<String, JsonNode>> it = props.fields(); while (it.hasNext()) { Entry<String,JsonNode> entry = it.next(); String name = entry.getKey(); if (_nameTransformer != null) { name = _nameTransformer.transform(name); } propertiesNode.set(name, entry.getValue()); } } } /* /********************************************************** /* Overrides: internal, other /********************************************************** */ // need to override as we must get unwrapping instance... @Override protected JsonSerializer<Object> _findAndAddDynamic(PropertySerializerMap map, Class<?> type, SerializerProvider provider) throws JsonMappingException { JsonSerializer<Object> serializer; if (_nonTrivialBaseType != null) { JavaType subtype = provider.constructSpecializedType(_nonTrivialBaseType, type); serializer = provider.findValueSerializer(subtype, this); } else { serializer = provider.findValueSerializer(type, this); } NameTransformer t = _nameTransformer; if (serializer.isUnwrappingSerializer() // as per [databind#2060], need to also check this, in case someone writes // custom implementation that does not extend standard implementation: && (serializer instanceof UnwrappingBeanSerializer)) { t = NameTransformer.chainedTransformer(t, ((UnwrappingBeanSerializer) serializer)._nameTransformer); } serializer = serializer.unwrappingSerializer(t); _dynamicSerializers = _dynamicSerializers.newWith(type, serializer); return serializer; } }
⏎ com/fasterxml/jackson/databind/ser/impl/UnwrappingBeanPropertyWriter.java
Or download all of them as a single archive file:
File name: jackson-databind-2.14.0-sources.jar File size: 1187952 bytes Release date: 2022-11-05 Download
⇒ Jackson Annotations Source Code
⇐ Download and Install Jackson Binary Package
2022-03-29, 109205👍, 0💬
Popular Posts:
What Is commons-codec-1.4.jar? commons-codec-1.4.jar is the JAR file for Apache Commons Codec 1.4, w...
How to display types defined in an XML Schema file with the xs\QueryXS.java provided in the Apache X...
What Is mail.jar of JavaMail 1.3? I got the JAR file from javamail-1_3.zip. mail.jar in javamail-1_3...
JDK 11 jdk.httpserver.jmod is the JMOD file for JDK 11 HTTP Server module. JDK 11 HTTP Server module...
HttpComponents Client Source Code Files are provided in the source package file, httpcomponents-clie...