• R/O
  • SSH
  • HTTPS

jsonic: コミット


コミットメタ情報

リビジョン1865 (tree)
日時2015-10-16 22:43:29
作者hizuno

ログメッセージ

version 1.3.10 beta1

変更サマリ

差分

--- trunk/jsonic-1.3/src/net/arnx/jsonic/JSONWriter.java (revision 1864)
+++ trunk/jsonic-1.3/src/net/arnx/jsonic/JSONWriter.java (revision 1865)
@@ -41,6 +41,7 @@
4141 } else if (state.type == JSONDataType.OBJECT) {
4242 if (state.name != null) {
4343 context.enter(state.name);
44+ state.index++;
4445 } else {
4546 throw new JSONException(
4647 context.getMessage("json.format.IllegalMethodCallError", "beginObject"),
@@ -53,6 +54,7 @@
5354 context.appendIndent(out, context.getDepth() + 1);
5455 }
5556 context.enter(state.index);
57+ state.index++;
5658 } else {
5759 throw new IllegalStateException();
5860 }
@@ -99,6 +101,7 @@
99101 } else if (state.type == JSONDataType.OBJECT) {
100102 if (state.name != null) {
101103 context.enter(state.name);
104+ state.index++;
102105 } else {
103106 throw new JSONException(
104107 context.getMessage("json.format.IllegalMethodCallError", "beginArray"),
@@ -111,6 +114,7 @@
111114 context.appendIndent(out, context.getDepth() + 1);
112115 }
113116 context.enter(state.index);
117+ state.index++;
114118 } else {
115119 throw new IllegalStateException();
116120 }
@@ -186,6 +190,7 @@
186190 } else if (state.type == JSONDataType.OBJECT) {
187191 if (state.name != null) {
188192 context.enter(state.name);
193+ state.index++;
189194 } else {
190195 throw new JSONException(
191196 context.getMessage("json.format.IllegalMethodCallError", "value"),
@@ -198,6 +203,7 @@
198203 context.appendIndent(out, context.getDepth() + 1);
199204 }
200205 context.enter(state.index);
206+ state.index++;
201207 } else {
202208 throw new IllegalStateException();
203209 }
@@ -206,10 +212,43 @@
206212 context.formatInternal(value, out);
207213 context.exit();
208214
209- if (state != null) {
215+ if (stack.size == 0) {
216+ out.flush();
217+ }
218+ return this;
219+ }
220+
221+ public JSONWriter append(String text) throws IOException {
222+ State state = stack.peek();
223+ if(state == null) {
224+ if (context.isPrettyPrint()) {
225+ context.appendIndent(out, 0);
226+ }
227+ context.enter(JSON.ROOT, null);
228+ } else if (state.type == JSONDataType.OBJECT) {
229+ if (state.name != null) {
230+ context.enter(state.name);
231+ state.index++;
232+ } else {
233+ throw new JSONException(
234+ context.getMessage("json.format.IllegalMethodCallError", "value"),
235+ JSONException.FORMAT_ERROR);
236+ }
237+ } else if (state.type == JSONDataType.ARRAY) {
238+ if (state.index > 0) out.append(',');
239+ if (context.isPrettyPrint()) {
240+ out.append('\n');
241+ context.appendIndent(out, context.getDepth() + 1);
242+ }
243+ context.enter(state.index);
210244 state.index++;
245+ } else {
246+ throw new IllegalStateException();
211247 }
212248
249+ out.append(text);
250+ context.exit();
251+
213252 if (stack.size == 0) {
214253 out.flush();
215254 }
--- trunk/jsonic-1.3/src/net/arnx/jsonic/JSONReader.java (revision 1864)
+++ trunk/jsonic-1.3/src/net/arnx/jsonic/JSONReader.java (revision 1865)
@@ -91,6 +91,31 @@
9191 return (Boolean)parser.getValue();
9292 }
9393
94+ void skipValue() throws IOException {
95+ if (type == null) {
96+ throw new IllegalStateException("you should call next.");
97+ }
98+
99+ int ilen = 0;
100+
101+ do {
102+ switch (type) {
103+ case START_OBJECT:
104+ case START_ARRAY:
105+ ilen++;
106+ break;
107+ case END_ARRAY:
108+ case END_OBJECT:
109+ ilen--;
110+ break;
111+ }
112+
113+ if (parser.isInterpretterMode() && ilen == 0) {
114+ break;
115+ }
116+ } while ((type = parser.next()) != null);
117+ }
118+
94119 Object getValue() throws IOException {
95120 if (type == null) {
96121 throw new IllegalStateException("you should call next.");
@@ -105,19 +130,11 @@
105130 do {
106131 switch (type) {
107132 case START_OBJECT:
108- case START_ARRAY:
133+ case START_ARRAY: {
109134 istack = iexpand(istack, ilen + 1);
110135 istack[ilen++] = olen;
111136 break;
112- case NAME:
113- case STRING:
114- case NUMBER:
115- case BOOLEAN:
116- case NULL:
117- Object value = parser.getValue();
118- ostack = oexpand(ostack, olen + 1);
119- ostack[olen++] = value;
120- break;
137+ }
121138 case END_ARRAY: {
122139 int start = istack[--ilen];
123140 int len = olen - start;
@@ -130,7 +147,7 @@
130147 ostack[olen++] = array;
131148 break;
132149 }
133- case END_OBJECT:
150+ case END_OBJECT: {
134151 int start = istack[--ilen];
135152 int len = olen - start;
136153 Map<Object, Object> object = new LinkedHashMap<Object, Object>(
@@ -146,6 +163,17 @@
146163 ostack[olen++] = object;
147164 break;
148165 }
166+ case NAME:
167+ case STRING:
168+ case NUMBER:
169+ case BOOLEAN:
170+ case NULL: {
171+ Object value = parser.getValue();
172+ ostack = oexpand(ostack, olen + 1);
173+ ostack[olen++] = value;
174+ break;
175+ }
176+ }
149177
150178 if (parser.isInterpretterMode() && ilen == 0) {
151179 break;
--- trunk/jsonic-1.3/docs/index.html (revision 1864)
+++ trunk/jsonic-1.3/docs/index.html (revision 1865)
@@ -869,6 +869,13 @@
869869
870870 <h2 id="releasenote">リリースノート</h2>
871871
872+<h3>2015/10/16 version 1.3.10</h3>
873+<ul>
874+<li>[不具合修正] JSONWriter にて配列中のオブジェクトや配列の後ろのカンマが出力されない問題を修正しました。</li>
875+<li>[機能追加] JSONReader にて値の読み取りをスキップしてメモリを節約できる skipValue() メソッドを追加しました。</li>
876+<li>[機能追加] JSONWriter にて値をそのまま出力できる append(String text) メソッドを追加しました。</li>
877+</ul>
878+
872879 <h3>2015/8/20 version 1.3.9</h3>
873880 <ul>
874881 <li>[不具合修正] Java8 Date/Time API に JSONHint の format が正しく反映されない問題を修正しました[チケット:#35349]</li>
--- trunk/jsonic-1.3/pom.xml (revision 1864)
+++ trunk/jsonic-1.3/pom.xml (revision 1865)
@@ -7,7 +7,7 @@
77 <artifactId>jsonic</artifactId>
88 <packaging>jar</packaging>
99 <name>jsonic</name>
10- <version>1.3.9</version>
10+ <version>1.3.10</version>
1111 <description>simple json encoder/decoder for java</description>
1212 <url>http://jsonic.sourceforge.jp/</url>
1313 <licenses>
--- trunk/jsonic-1.3/test/net/arnx/jsonic/JSONWriterTest.java (revision 1864)
+++ trunk/jsonic-1.3/test/net/arnx/jsonic/JSONWriterTest.java (revision 1865)
@@ -89,6 +89,63 @@
8989 w.value("hoge");
9090 w.endObject();
9191 assertEquals("{\n\t\"hoge\": \"hoge\",\n\t\"hoge2\": [\n\t\t\"hoge\",\n\t\t[\n\t\t\t\"hoge\"\n\t\t]\n\t],\n\t\"hoge3\": \"hoge\"\n}", out.toString());
92+
93+
94+ out.getBuffer().setLength(0);
95+ w = json.getWriter(out);
96+ w.beginArray();
97+ {
98+ w.beginObject();
99+ {
100+ w.name("hoge");
101+ w.value("hoge");
102+ w.name("object");
103+ w.beginObject();
104+ w.endObject();
105+ }
106+ w.endObject();
107+ w.beginObject();
108+ {
109+ w.name("hoge");
110+ w.value("hoge");
111+ w.name("array");
112+ w.beginArray();
113+ w.endArray();
114+ }
115+ w.endObject();
116+ w.beginArray();
117+ {
118+ w.beginObject();
119+ w.endObject();
120+ w.value("hoge");
121+ w.beginArray();
122+ w.endArray();
123+ }
124+ w.endArray();
125+ }
126+ w.endArray();
127+ assertEquals("[\n\t{\n\t\t\"hoge\": \"hoge\",\n\t\t\"object\": {}\n\t},\n\t{\n\t\t\"hoge\": \"hoge\",\n\t\t\"array\": []\n\t},\n\t[\n\t\t{},\n\t\t\"hoge\",\n\t\t[]\n\t]\n]", out.toString());
128+
129+
130+ out.getBuffer().setLength(0);
131+ w = json.getWriter(out);
132+ w.beginArray();
133+ {
134+ w.beginObject();
135+ {
136+ w.name("hoge");
137+ w.append("{\"hoge\":\"hoge\",\"object\":{}}");
138+ }
139+ w.endObject();
140+ w.beginArray();
141+ {
142+ w.append("{\"hoge\":\"hoge\",\"array\":[]}");
143+ }
144+ w.endArray();
145+ }
146+ w.endArray();
147+ assertEquals("[\n\t{\n\t\t\"hoge\": {\"hoge\":\"hoge\",\"object\":{}}\n\t},\n\t[\n\t\t{\"hoge\":\"hoge\",\"array\":[]}\n\t]\n]", out.toString());
148+
92149 }
93150
94151 @Test
旧リポジトリブラウザで表示