Categories:
Audio (13)
Biotech (29)
Bytecode (36)
Database (77)
Framework (7)
Game (7)
General (507)
Graphics (53)
I/O (35)
IDE (2)
JAR Tools (102)
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 (322)
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/std/UUIDSerializer.java
package com.fasterxml.jackson.databind.ser.std;
import java.io.IOException;
import java.util.Objects;
import java.util.UUID;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonValueFormat;
import com.fasterxml.jackson.databind.ser.ContextualSerializer;
import com.fasterxml.jackson.databind.util.TokenBuffer;
/**
* Specialized {@link JsonSerializer} to output {@link java.util.UUID}s.
* Beyond optimized access and writing of textual representation (which
* is the default handling in most cases), it will alternatively
* allow serialization using raw binary output (as 16-byte block)
* if underlying data format has efficient means to access that.
*/
@SuppressWarnings("serial")
public class UUIDSerializer
extends StdScalarSerializer<UUID>
implements ContextualSerializer // since 2.11.3 (for databind#2815)
{
final static char[] HEX_CHARS = "0123456789abcdef".toCharArray();
/**
* Configuration setting that indicates if serialization as binary
* (native or Base64-encoded) has been forced; {@code null} means
* "use default heuristic"
*
* @since 2.11.3
*/
protected final Boolean _asBinary;
public UUIDSerializer() { this(null); }
/**
* @since 2.11.3
*/
protected UUIDSerializer(Boolean asBinary) {
super(UUID.class);
_asBinary = asBinary;
}
@Override
public boolean isEmpty(SerializerProvider prov, UUID value)
{
// Null UUID is empty, so...
if (value.getLeastSignificantBits() == 0L
&& value.getMostSignificantBits() == 0L) {
return true;
}
return false;
}
@Override
public JsonSerializer<?> createContextual(SerializerProvider serializers,
BeanProperty property) throws JsonMappingException
{
JsonFormat.Value format = findFormatOverrides(serializers,
property, handledType());
Boolean asBinary = null;
if (format != null) {
JsonFormat.Shape shape = format.getShape();
if (shape == JsonFormat.Shape.BINARY) {
asBinary = true;
} else if (shape == JsonFormat.Shape.STRING) {
asBinary = false;
}
// otherwise leave as `null` meaning about same as NATURAL
}
if (!Objects.equals(asBinary, _asBinary)) {
return new UUIDSerializer(asBinary);
}
return this;
}
@Override
public void serialize(UUID value, JsonGenerator gen, SerializerProvider provider)
throws IOException
{
// First: perhaps we could serialize it as raw binary data?
if (_writeAsBinary(gen)) {
gen.writeBinary(_asBytes(value));
return;
}
// UUID.toString() works ok functionally, but we can make it go much faster
// (by 4x with micro-benchmark)
final char[] ch = new char[36];
final long msb = value.getMostSignificantBits();
_appendInt((int) (msb >> 32), ch, 0);
ch[8] = '-';
int i = (int) msb;
_appendShort(i >>> 16, ch, 9);
ch[13] = '-';
_appendShort(i, ch, 14);
ch[18] = '-';
final long lsb = value.getLeastSignificantBits();
_appendShort((int) (lsb >>> 48), ch, 19);
ch[23] = '-';
_appendShort((int) (lsb >>> 32), ch, 24);
_appendInt((int) lsb, ch, 28);
gen.writeString(ch, 0, 36);
}
// @since 2.11.3
protected boolean _writeAsBinary(JsonGenerator g)
{
if (_asBinary != null) {
return _asBinary;
}
// 07-Dec-2013, tatu: One nasty case; that of TokenBuffer. While it can
// technically retain binary data, we do not want to do use binary
// with it, as that results in UUIDs getting converted to Base64 for
// most conversions.
return !(g instanceof TokenBuffer) && g.canWriteBinaryNatively();
}
// Need to add bit of extra info, format
@Override
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint)
throws JsonMappingException
{
visitStringFormat(visitor, typeHint, JsonValueFormat.UUID);
}
private static void _appendInt(int bits, char[] ch, int offset)
{
_appendShort(bits >> 16, ch, offset);
_appendShort(bits, ch, offset+4);
}
private static void _appendShort(int bits, char[] ch, int offset)
{
ch[offset] = HEX_CHARS[(bits >> 12) & 0xF];
ch[++offset] = HEX_CHARS[(bits >> 8) & 0xF];
ch[++offset] = HEX_CHARS[(bits >> 4) & 0xF];
ch[++offset] = HEX_CHARS[bits & 0xF];
}
private final static byte[] _asBytes(UUID uuid)
{
byte[] buffer = new byte[16];
long hi = uuid.getMostSignificantBits();
long lo = uuid.getLeastSignificantBits();
_appendInt((int) (hi >> 32), buffer, 0);
_appendInt((int) hi, buffer, 4);
_appendInt((int) (lo >> 32), buffer, 8);
_appendInt((int) lo, buffer, 12);
return buffer;
}
private final static void _appendInt(int value, byte[] buffer, int offset)
{
buffer[offset] = (byte) (value >> 24);
buffer[++offset] = (byte) (value >> 16);
buffer[++offset] = (byte) (value >> 8);
buffer[++offset] = (byte) value;
}
}
⏎ com/fasterxml/jackson/databind/ser/std/UUIDSerializer.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, ≈297🔥, 0💬
Popular Posts:
JDK 17 jdk.incubator.foreign.jm odis the JMOD file for JDK 17 HTTP Server module. JDK 17 Incubator F...
JDK 11 jdk.javadoc.jmod is the JMOD file for JDK 11 Java Document tool, which can be invoked by the ...
How to compare performances of various XML parsers with the jaxp\SourceValidator.jav aprovided in th...
maven-embedder-3.8.6.jar is the JAR file for Apache Maven 3.8.6 Embedder module. Apache Maven is a s...
JDK 17 jdk.internal.opt.jmod is the JMOD file for JDK 17 Internal Opt module. JDK 17 Internal Opt mo...