Skip to content

Commit fab0c6c

Browse files
committed
Stat #60 implementation
1 parent dc630e6 commit fab0c6c

File tree

4 files changed

+605
-3
lines changed

4 files changed

+605
-3
lines changed

jr-objects/src/main/java/com/fasterxml/jackson/jr/ob/JSON.java

+99-3
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,30 @@
1717
import com.fasterxml.jackson.jr.ob.impl.*;
1818

1919
/**
20-
* Main entry point for functionality.
20+
* Main entry point for functionality for reading and writing JSON
21+
* and configuring details of reading and writing.
2122
*<p>
2223
* Note that instances are fully immutable, and thereby thread-safe.
24+
*<p>
25+
* Note on source types: source to read is declared as {@link java.lang.Object}
26+
* but covers following types:
27+
*<ul>
28+
* <li>{@link InputStream}</li>
29+
* <li>{@link Reader}</li>
30+
* <li>{@code byte[]}</li>
31+
* <li>{@code char[]}</li>
32+
* <li>{@link String}/{@link CharSequence}</li>
33+
* <li>{@link URL}</li>
34+
* <li>{@link File}</li>
35+
* </ul>
36+
*
2337
*/
2438
@SuppressWarnings("resource")
2539
public class JSON implements Versioned
2640
{
2741
/**
28-
* Simple on/off (enabled/disabled) features for {@link JSON}; used for simple configuration
29-
* aspects.
42+
* Simple on/off (enabled/disabled) features for {@link JSON}; used for simple
43+
* configuration aspects.
3044
*/
3145
public enum Feature
3246
{
@@ -651,6 +665,34 @@ public final boolean isEnabled(Feature f) {
651665
return (f.mask() & _features) != 0;
652666
}
653667

668+
/*
669+
/**********************************************************************
670+
/* Public factory methods for parsers, generators
671+
/**********************************************************************
672+
*/
673+
674+
/**
675+
* Factory method for opening a {@link JsonParser} to read content from one of
676+
* following supported sources
677+
*<ul>
678+
* <li>{@link InputStream}</li>
679+
* <li>{@link Reader}</li>
680+
* <li>{@code byte[]}</li>
681+
* <li>{@code char[]}</li>
682+
* <li>{@link String}/{@link CharSequence}</li>
683+
* <li>{@link URL}</li>
684+
* <li>{@link File}</li>
685+
* </ul>
686+
*<p>
687+
* Rules regarding closing of the underlying source follow rules
688+
* that {@link JsonFactory} has for its {@code createParser} method.
689+
*
690+
* @since 2.10
691+
*/
692+
public JsonParser createParser(Object source) throws IOException, JSONObjectException {
693+
return _parser(source);
694+
}
695+
654696
/*
655697
/**********************************************************************
656698
/* API: writing Simple objects as JSON
@@ -971,6 +1013,60 @@ public <T extends TreeNode> TreeNode treeFrom(Object source)
9711013
}
9721014
}
9731015

1016+
/*
1017+
/**********************************************************************
1018+
/* API: reading sequence of JSON values (LD-JSON and like)
1019+
/**********************************************************************
1020+
*/
1021+
1022+
/**
1023+
* Method for creating {@link ValueIterator} for reading
1024+
* <a href="https://en.wikipedia.org/wiki/JSON_streaming">streaming JSON</a>
1025+
* content (specifically line-delimited and concatenated variants);
1026+
* individual values are bound to specific Bean (POJO) type.
1027+
*
1028+
* @since 2.10
1029+
*/
1030+
public <T> ValueIterator<T> beanSequenceFrom(Class<T> type, Object source)
1031+
throws IOException, JSONObjectException
1032+
{
1033+
JsonParser p;
1034+
final boolean managed = !(source instanceof JsonParser);
1035+
1036+
if (managed) {
1037+
p = _parser(source);
1038+
} else {
1039+
p = (JsonParser) source;
1040+
}
1041+
p = _initForReading(_config(p));
1042+
JSONReader reader = _readerForOperation(p);
1043+
return new ValueIterator<T>(ValueIterator.MODE_BEAN, type, p, reader, managed);
1044+
}
1045+
1046+
/**
1047+
* Method for creating {@link ValueIterator} for reading
1048+
* <a href="https://en.wikipedia.org/wiki/JSON_streaming">streaming JSON</a>
1049+
* content (specifically line-delimited and concatenated variants);
1050+
* individual values are bound as "Any" type: {@link java.util.Map},
1051+
* {@link java.util.List}, {@link String}, {@link Number} or {@link Boolean}.
1052+
*
1053+
* @since 2.10
1054+
*/
1055+
public ValueIterator<Object> anySequenceFrom(Object source) throws IOException
1056+
{
1057+
JsonParser p;
1058+
final boolean managed = !(source instanceof JsonParser);
1059+
1060+
if (managed) {
1061+
p = _parser(source);
1062+
} else {
1063+
p = (JsonParser) source;
1064+
}
1065+
p = _initForReading(_config(p));
1066+
JSONReader reader = _readerForOperation(p);
1067+
return new ValueIterator<Object>(ValueIterator.MODE_ANY, Object.class, p, reader, managed);
1068+
}
1069+
9741070
/*
9751071
/**********************************************************************
9761072
/* API: TreeNode construction

0 commit comments

Comments
 (0)