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/node/NodeCursor.java
package com.fasterxml.jackson.databind.node;
import java.util.*;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.JsonNode;
/**
* Helper class used by {@link TreeTraversingParser} to keep track
* of current location within traversed JSON tree.
*/
abstract class NodeCursor
extends JsonStreamContext
{
/**
* Parent cursor of this cursor, if any; null for root
* cursors.
*/
protected final NodeCursor _parent;
/**
* Current field name
*/
protected String _currentName;
/**
* @since 2.5
*/
protected java.lang.Object _currentValue;
public NodeCursor(int contextType, NodeCursor p)
{
super();
_type = contextType;
_index = -1;
_parent = p;
}
/*
/**********************************************************
/* JsonStreamContext impl
/**********************************************************
*/
// note: co-variant return type
@Override
public final NodeCursor getParent() { return _parent; }
@Override
public final String getCurrentName() {
return _currentName;
}
/**
* @since 2.0
*/
public void overrideCurrentName(String name) {
_currentName = name;
}
@Override
public java.lang.Object getCurrentValue() {
return _currentValue;
}
@Override
public void setCurrentValue(java.lang.Object v) {
_currentValue = v;
}
/*
/**********************************************************
/* Extended API
/**********************************************************
*/
public abstract JsonToken nextToken();
public abstract JsonNode currentNode();
public abstract NodeCursor startObject();
public abstract NodeCursor startArray();
/**
* Method called to create a new context for iterating all
* contents of the current structured value (JSON array or object)
*/
public final NodeCursor iterateChildren() {
JsonNode n = currentNode();
if (n == null) throw new IllegalStateException("No current node");
if (n.isArray()) { // false since we have already returned START_ARRAY
return new ArrayCursor(n, this);
}
if (n.isObject()) {
return new ObjectCursor(n, this);
}
throw new IllegalStateException("Current node of type "+n.getClass().getName());
}
/*
/**********************************************************
/* Concrete implementations
/**********************************************************
*/
/**
* Context for all root-level value nodes (including Arrays and Objects):
* only context for scalar values.
*/
protected final static class RootCursor
extends NodeCursor
{
protected JsonNode _node;
protected boolean _done = false;
public RootCursor(JsonNode n, NodeCursor p) {
super(JsonStreamContext.TYPE_ROOT, p);
_node = n;
}
@Override
public void overrideCurrentName(String name) {
}
@Override
public JsonToken nextToken() {
if (!_done) {
++_index;
_done = true;
return _node.asToken();
}
_node = null;
return null;
}
@Override
public JsonNode currentNode() {
// May look weird, but is necessary so as not to expose current node
// before it has been traversed
return _done ? _node : null;
}
@Override
public NodeCursor startArray() { return new ArrayCursor(_node, this); }
@Override
public NodeCursor startObject() { return new ObjectCursor(_node, this); }
}
// Cursor used for traversing JSON Array nodes
protected final static class ArrayCursor
extends NodeCursor
{
protected Iterator<JsonNode> _contents;
protected JsonNode _currentElement;
public ArrayCursor(JsonNode n, NodeCursor p) {
super(JsonStreamContext.TYPE_ARRAY, p);
_contents = n.elements();
}
@Override
public JsonToken nextToken()
{
if (!_contents.hasNext()) {
_currentElement = null;
return JsonToken.END_ARRAY;
}
++_index;
_currentElement = _contents.next();
return _currentElement.asToken();
}
@Override
public JsonNode currentNode() { return _currentElement; }
@Override
public NodeCursor startArray() { return new ArrayCursor(_currentElement, this); }
@Override
public NodeCursor startObject() { return new ObjectCursor(_currentElement, this); }
}
// Cursor used for traversing JSON Object nodes
protected final static class ObjectCursor
extends NodeCursor
{
protected Iterator<Map.Entry<String, JsonNode>> _contents;
protected Map.Entry<String, JsonNode> _current;
protected boolean _needEntry;
public ObjectCursor(JsonNode n, NodeCursor p)
{
super(JsonStreamContext.TYPE_OBJECT, p);
_contents = ((ObjectNode) n).fields();
_needEntry = true;
}
@Override
public JsonToken nextToken()
{
// Need a new entry?
if (_needEntry) {
if (!_contents.hasNext()) {
_currentName = null;
_current = null;
return JsonToken.END_OBJECT;
}
++_index;
_needEntry = false;
_current = _contents.next();
_currentName = (_current == null) ? null : _current.getKey();
return JsonToken.FIELD_NAME;
}
_needEntry = true;
return _current.getValue().asToken();
}
@Override
public JsonNode currentNode() {
return (_current == null) ? null : _current.getValue();
}
@Override
public NodeCursor startArray() { return new ArrayCursor(currentNode(), this); }
@Override
public NodeCursor startObject() { return new ObjectCursor(currentNode(), this); }
}
}
⏎ com/fasterxml/jackson/databind/node/NodeCursor.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, ≈232🔥, 0💬
Popular Posts:
jlGui is a music player for the Java platform. It is based on Java Sound 1.0 (i.e. JDK 1.3+). It sup...
JDK 17 java.naming.jmod is the JMOD file for JDK 17 Naming module. JDK 17 Naming module compiled cla...
JDK 11 java.rmi.jmod is the JMOD file for JDK 11 RMI (Remote Method Invocation) module. JDK 11 RMI m...
JDK 11 java.base.jmod is the JMOD file for JDK 11 Base module. JDK 11 Base module compiled class fil...
JDK 11 java.management.jmod is the JMOD file for JDK 11 Management module. JDK 11 Management module ...