Skip to content

Commit

Permalink
Stat #60 implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Aug 22, 2019
1 parent dc630e6 commit fab0c6c
Show file tree
Hide file tree
Showing 4 changed files with 605 additions and 3 deletions.
102 changes: 99 additions & 3 deletions jr-objects/src/main/java/com/fasterxml/jackson/jr/ob/JSON.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,30 @@
import com.fasterxml.jackson.jr.ob.impl.*;

/**
* Main entry point for functionality.
* Main entry point for functionality for reading and writing JSON
* and configuring details of reading and writing.
*<p>
* Note that instances are fully immutable, and thereby thread-safe.
*<p>
* Note on source types: source to read is declared as {@link java.lang.Object}
* but covers following types:
*<ul>
* <li>{@link InputStream}</li>
* <li>{@link Reader}</li>
* <li>{@code byte[]}</li>
* <li>{@code char[]}</li>
* <li>{@link String}/{@link CharSequence}</li>
* <li>{@link URL}</li>
* <li>{@link File}</li>
* </ul>
*
*/
@SuppressWarnings("resource")
public class JSON implements Versioned
{
/**
* Simple on/off (enabled/disabled) features for {@link JSON}; used for simple configuration
* aspects.
* Simple on/off (enabled/disabled) features for {@link JSON}; used for simple
* configuration aspects.
*/
public enum Feature
{
Expand Down Expand Up @@ -651,6 +665,34 @@ public final boolean isEnabled(Feature f) {
return (f.mask() & _features) != 0;
}

/*
/**********************************************************************
/* Public factory methods for parsers, generators
/**********************************************************************
*/

/**
* Factory method for opening a {@link JsonParser} to read content from one of
* following supported sources
*<ul>
* <li>{@link InputStream}</li>
* <li>{@link Reader}</li>
* <li>{@code byte[]}</li>
* <li>{@code char[]}</li>
* <li>{@link String}/{@link CharSequence}</li>
* <li>{@link URL}</li>
* <li>{@link File}</li>
* </ul>
*<p>
* Rules regarding closing of the underlying source follow rules
* that {@link JsonFactory} has for its {@code createParser} method.
*
* @since 2.10
*/
public JsonParser createParser(Object source) throws IOException, JSONObjectException {
return _parser(source);
}

/*
/**********************************************************************
/* API: writing Simple objects as JSON
Expand Down Expand Up @@ -971,6 +1013,60 @@ public <T extends TreeNode> TreeNode treeFrom(Object source)
}
}

/*
/**********************************************************************
/* API: reading sequence of JSON values (LD-JSON and like)
/**********************************************************************
*/

/**
* Method for creating {@link ValueIterator} for reading
* <a href="https://en.wikipedia.org/wiki/JSON_streaming">streaming JSON</a>
* content (specifically line-delimited and concatenated variants);
* individual values are bound to specific Bean (POJO) type.
*
* @since 2.10
*/
public <T> ValueIterator<T> beanSequenceFrom(Class<T> type, Object source)
throws IOException, JSONObjectException
{
JsonParser p;
final boolean managed = !(source instanceof JsonParser);

if (managed) {
p = _parser(source);
} else {
p = (JsonParser) source;
}
p = _initForReading(_config(p));
JSONReader reader = _readerForOperation(p);
return new ValueIterator<T>(ValueIterator.MODE_BEAN, type, p, reader, managed);
}

/**
* Method for creating {@link ValueIterator} for reading
* <a href="https://en.wikipedia.org/wiki/JSON_streaming">streaming JSON</a>
* content (specifically line-delimited and concatenated variants);
* individual values are bound as "Any" type: {@link java.util.Map},
* {@link java.util.List}, {@link String}, {@link Number} or {@link Boolean}.
*
* @since 2.10
*/
public ValueIterator<Object> anySequenceFrom(Object source) throws IOException
{
JsonParser p;
final boolean managed = !(source instanceof JsonParser);

if (managed) {
p = _parser(source);
} else {
p = (JsonParser) source;
}
p = _initForReading(_config(p));
JSONReader reader = _readerForOperation(p);
return new ValueIterator<Object>(ValueIterator.MODE_ANY, Object.class, p, reader, managed);
}

/*
/**********************************************************************
/* API: TreeNode construction
Expand Down
Loading

0 comments on commit fab0c6c

Please sign in to comment.