Java Reference
In-Depth Information
ject (by calling the Json.createJsonReaderFactory() method). The reader factory can be
configured via a Map of properties, although the JSR 353 RI does not presently support any
configuration options. JsonReader objects are not reusable.
DOMs are expensive to create compared to simply parsing the corresponding data, as shown
in Table 10-8 .
Table 10-8. Performance of DOM parsing
Time required to XML
JSON
Parse data
265 ms 146 ms
Build document
348 ms 197 ms
The time to build the document includes parsing time, plus the time to create the document
object structure—so it can be inferred from this table that the time to create the structure is
roughly 33% of the total time for XML, and 25% of the total time of JSON. More complic-
ated documents may show a larger percentage of time spent building the document model.
The previous parsing tests were sometimes only interested in the first 10 items. If the object
representation similarly should contain only the first 10 items, then there are two choices.
First, the object can be created, and then various methods can be used to walk through the
object and discard any undesired items. That is the only option for JSON objects.
DOM objects can set up a filtering parser using DOM level 3 attributes. This first requires
that a parsing filter be created:
private
private class
class InputFilter
InputFilter implements
implements LSParserFilter {
private
private boolean
boolean done = false
false ;
private
private boolean
boolean itemCountReached ;
public
public short
short acceptNode ( Node node ) {
iif ( itemCountReached ) {
String s = node . getNodeName ();
iif ( "ItemArray" . equals ( s )) {
return
return NodeFilter . FILTER_ACCEPT ;
}
iif ( done ) {
return
return NodeFilter . FILTER_SKIP ;
}
Search WWH ::




Custom Search