@@ -37,14 +37,20 @@ class HjsonParser {
3737 private int current ;
3838 private StringBuilder captureBuffer , peek ;
3939 private boolean capture ;
40+ private boolean legacyRoot ;
4041
4142 private IHjsonDsfProvider [] dsfProviders ;
4243
4344 HjsonParser (String string , HjsonOptions options ) {
4445 buffer =string ;
4546 reset ();
46- if (options !=null ) dsfProviders =options .getDsfProviders ();
47- else dsfProviders =new IHjsonDsfProvider [0 ];
47+ if (options !=null ) {
48+ dsfProviders =options .getDsfProviders ();
49+ legacyRoot =options .getParseLegacyRoot ();
50+ } else {
51+ dsfProviders =new IHjsonDsfProvider [0 ];
52+ legacyRoot =true ;
53+ }
4854 }
4955
5056 HjsonParser (Reader reader , HjsonOptions options ) throws IOException {
@@ -75,23 +81,27 @@ JsonValue parse() throws IOException {
7581 read ();
7682 skipWhiteSpace ();
7783
78- switch (current ) {
79- case '[' :
80- case '{' :
81- return checkTrailing (readValue ());
82- default :
83- try {
84- // assume we have a root object without braces
85- return checkTrailing (readObject (true ));
86- } catch (Exception exception ) {
87- // test if we are dealing with a single JSON value instead (true/false/null/num/"")
88- reset ();
89- read ();
90- skipWhiteSpace ();
91- try { return checkTrailing (readValue ()); }
92- catch (Exception exception2 ) { }
93- throw exception ; // throw original error
94- }
84+ if (legacyRoot ) {
85+ switch (current ) {
86+ case '[' :
87+ case '{' :
88+ return checkTrailing (readValue ());
89+ default :
90+ try {
91+ // assume we have a root object without braces
92+ return checkTrailing (readObject (true ));
93+ } catch (Exception exception ) {
94+ // test if we are dealing with a single JSON value instead (true/false/null/num/"")
95+ reset ();
96+ read ();
97+ skipWhiteSpace ();
98+ try { return checkTrailing (readValue ()); }
99+ catch (Exception exception2 ) { }
100+ throw exception ; // throw original error
101+ }
102+ }
103+ } else {
104+ return checkTrailing (readValue ());
95105 }
96106 }
97107
0 commit comments