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/BeanAsArraySerializer.java
package com.fasterxml.jackson.databind.ser.impl; import java.io.IOException; import java.util.Set; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.core.type.WritableTypeId; import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; import com.fasterxml.jackson.databind.ser.BeanPropertyWriter; import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase; import com.fasterxml.jackson.databind.util.NameTransformer; /** * Specialized POJO serializer that differs from * {@link com.fasterxml.jackson.databind.ser.BeanSerializer} * in that instead of producing a JSON Object it will output * a JSON Array, omitting field names, and serializing values in * specified serialization order. * This behavior is usually triggered by using annotation * {@link com.fasterxml.jackson.annotation.JsonFormat} or its * equivalents. *<p> * This serializer can be used for "simple" instances; and will NOT * be used if one of following is true: *<ul> * <li>Unwrapping is used (no way to expand out array in JSON Object) * </li> * <li>Type information ("type id") is to be used: while this could work * for some embedding methods, it would likely cause conflicts. * </li> * <li>Object Identity ("object id") is used: while references would work, * the problem is inclusion of id itself. * </li> *</ul> * Note that it is theoretically possible that last 2 issues could be addressed * (by reserving room in array, for example); and if so, support improved. *<p> * In cases where array-based output is not feasible, this serializer * can instead delegate to the original Object-based serializer; this * is why a reference is retained to the original serializer. * * @since 2.1 */ public class BeanAsArraySerializer extends BeanSerializerBase { private static final long serialVersionUID = 1L; // since 2.6 /** * Serializer that would produce JSON Object version; used in * cases where array output cannot be used. */ protected final BeanSerializerBase _defaultSerializer; /* /********************************************************** /* Life-cycle: constructors /********************************************************** */ public BeanAsArraySerializer(BeanSerializerBase src) { super(src, (ObjectIdWriter) null); _defaultSerializer = src; } protected BeanAsArraySerializer(BeanSerializerBase src, Set<String> toIgnore) { this(src, toIgnore, null); } protected BeanAsArraySerializer(BeanSerializerBase src, Set<String> toIgnore, Set<String> toInclude) { super(src, toIgnore, toInclude); _defaultSerializer = src; } protected BeanAsArraySerializer(BeanSerializerBase src, ObjectIdWriter oiw, Object filterId) { super(src, oiw, filterId); _defaultSerializer = src; } /* /********************************************************** /* Life-cycle: factory methods, fluent factories /********************************************************** */ @Override public JsonSerializer<Object> unwrappingSerializer(NameTransformer transformer) { /* If this gets called, we will just need delegate to the default * serializer, to "undo" as-array serialization */ return _defaultSerializer.unwrappingSerializer(transformer); } @Override public boolean isUnwrappingSerializer() { return false; } @Override public BeanSerializerBase withObjectIdWriter(ObjectIdWriter objectIdWriter) { // can't handle Object Ids, for now, so: return _defaultSerializer.withObjectIdWriter(objectIdWriter); } @Override public BeanSerializerBase withFilterId(Object filterId) { return new BeanAsArraySerializer(this, _objectIdWriter, filterId); } @Override // @since 2.12 protected BeanAsArraySerializer withByNameInclusion(Set<String> toIgnore, Set<String> toInclude) { return new BeanAsArraySerializer(this, toIgnore, toInclude); } @Override // @since 2.11.1 protected BeanSerializerBase withProperties(BeanPropertyWriter[] properties, BeanPropertyWriter[] filteredProperties) { // 16-Jun-2020, tatu: Added for [databind#2759] but with as-array we // probably do not want to reorder anything; so actually leave unchanged return this; } @Override protected BeanSerializerBase asArraySerializer() { // already is one, so: return this; } /* /********************************************************** /* JsonSerializer implementation that differs between impls /********************************************************** */ // Re-defined from base class, due to differing prefixes @Override public void serializeWithType(Object bean, JsonGenerator gen, SerializerProvider provider, TypeSerializer typeSer) throws IOException { /* 10-Dec-2014, tatu: Not sure if this can be made to work reliably; * but for sure delegating to default implementation will not work. So: */ if (_objectIdWriter != null) { _serializeWithObjectId(bean, gen, provider, typeSer); return; } WritableTypeId typeIdDef = _typeIdDef(typeSer, bean, JsonToken.START_ARRAY); typeSer.writeTypePrefix(gen, typeIdDef); gen.setCurrentValue(bean); serializeAsArray(bean, gen, provider); typeSer.writeTypeSuffix(gen, typeIdDef); } /** * Main serialization method that will delegate actual output to * configured * {@link BeanPropertyWriter} instances. */ @Override public final void serialize(Object bean, JsonGenerator gen, SerializerProvider provider) throws IOException { if (provider.isEnabled(SerializationFeature.WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED) && hasSingleElement(provider)) { serializeAsArray(bean, gen, provider); return; } /* note: it is assumed here that limitations (type id, object id, * any getter, filtering) have already been checked; so code here * is trivial. */ gen.writeStartArray(bean); serializeAsArray(bean, gen, provider); gen.writeEndArray(); } /* /********************************************************** /* Field serialization methods /********************************************************** */ private boolean hasSingleElement(SerializerProvider provider) { final BeanPropertyWriter[] props; if (_filteredProps != null && provider.getActiveView() != null) { props = _filteredProps; } else { props = _props; } return props.length == 1; } protected final void serializeAsArray(Object bean, JsonGenerator gen, SerializerProvider provider) throws IOException { final BeanPropertyWriter[] props; if (_filteredProps != null && provider.getActiveView() != null) { props = _filteredProps; } else { props = _props; } int i = 0; try { for (final int len = props.length; i < len; ++i) { BeanPropertyWriter prop = props[i]; if (prop == null) { // can have nulls in filtered list; but if so, MUST write placeholders gen.writeNull(); } else { prop.serializeAsElement(bean, gen, provider); } } // NOTE: any getters cannot be supported either //if (_anyGetterWriter != null) { // _anyGetterWriter.getAndSerialize(bean, gen, provider); //} } catch (Exception e) { wrapAndThrow(provider, e, bean, props[i].getName()); } catch (StackOverflowError e) { DatabindException mapE = JsonMappingException.from(gen, "Infinite recursion (StackOverflowError)", e); mapE.prependPath(bean, props[i].getName()); throw mapE; } } /* /********************************************************** /* Standard methods /********************************************************** */ @Override public String toString() { return "BeanAsArraySerializer for "+handledType().getName(); } }
⏎ com/fasterxml/jackson/databind/ser/impl/BeanAsArraySerializer.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, 111409👍, 0💬
Popular Posts:
What Is ojdbc14.jar for Oracle 10g R2? ojdbc14.jar for Oracle 10g R2 is the JAR files of ojdbc.jar, ...
What Is commons-logging-1.2.jar? commons-logging-1.2.jar is the JAR file for Apache Commons Logging ...
JDK 11 jdk.internal.vm.compiler .jmodis the JMOD file for JDK 11 Internal VM Compiler module. JDK 11...
HttpComponents Core Source Code Files are provided in the source package file, httpcomponents-core-5...
What Is activation.jar? I heard it's related to JAF (JavaBeans Activation Framework) 1.1? The if you...