Permalink
Browse files

removing useless Structure abstraction

  • Loading branch information...
1 parent 1493089 commit 522d9e10a70f035a2b56503b9df00f561b1bb721 @ropalka ropalka committed Sep 14, 2012
@@ -19,12 +19,15 @@
*/
package org.fossnova.json;
+import java.io.IOException;
import java.util.List;
+import org.fossnova.json.stream.JsonWriter;
+
/**
* @author <a href="mailto:opalka dot richard at gmail dot com">Richard Opalka</a>
*/
-public interface JsonArray extends JsonStructure, List< JsonValue > {
+public interface JsonArray extends JsonValue, List< JsonValue > {
boolean add( final String value );
@@ -88,4 +91,6 @@
JsonValue[] toArray();
+ void writeTo( JsonWriter writer ) throws IOException;
+
}
@@ -44,6 +44,6 @@ public static JsonFactory newInstance() {
public abstract JsonArray newJsonArray();
- public abstract JsonStructure readFrom( JsonReader reader ) throws IOException;
+ public abstract JsonValue readFrom( JsonReader reader ) throws IOException;
}
@@ -19,12 +19,15 @@
*/
package org.fossnova.json;
+import java.io.IOException;
import java.util.Map;
+import org.fossnova.json.stream.JsonWriter;
+
/**
* @author <a href="mailto:opalka dot richard at gmail dot com">Richard Opalka</a>
*/
-public interface JsonObject extends JsonStructure, Map< String, JsonValue > {
+public interface JsonObject extends JsonValue, Map< String, JsonValue > {
boolean containsKey( final String key );
@@ -46,4 +49,6 @@
JsonValue remove( final String key );
+ void writeTo( JsonWriter writer ) throws IOException;
+
}
@@ -1,31 +0,0 @@
-/*
- * Copyright (c) 2012, FOSS Nova Software foundation (FNSF),
- * and individual contributors as indicated by the @author tags.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.fossnova.json;
-
-import java.io.IOException;
-
-import org.fossnova.json.stream.JsonWriter;
-
-/**
- * @author <a href="mailto:opalka dot richard at gmail dot com">Richard Opalka</a>
- */
-public interface JsonStructure extends JsonValue {
- void writeTo( JsonWriter writer ) throws IOException;
-}
@@ -31,7 +31,6 @@
import java.io.IOException;
import org.fossnova.json.JsonFactory;
-import org.fossnova.json.JsonStructure;
import org.fossnova.json.JsonValue;
import org.fossnova.json.stream.JsonEvent;
import org.fossnova.json.stream.JsonReader;
@@ -54,14 +53,14 @@ public JsonArrayImpl newJsonArray() {
}
@Override
- public JsonStructure readFrom( final JsonReader jsonReader ) throws IOException {
+ public JsonValue readFrom( final JsonReader jsonReader ) throws IOException {
if ( jsonReader == null ) {
throw new IllegalArgumentException( "JSON reader cannot be null" );
}
return readFrom( (JsonReaderImpl) jsonReader );
}
- private JsonStructure readFrom( final JsonReaderImpl jsonReader ) throws IOException {
+ private JsonValue readFrom( final JsonReaderImpl jsonReader ) throws IOException {
if ( jsonReader.next() == OBJECT_START ) {
return readJsonObjectFrom( jsonReader );
} else {
@@ -23,15 +23,15 @@
import java.math.BigDecimal;
import java.math.BigInteger;
-import org.fossnova.json.JsonStructure;
+import org.fossnova.json.JsonValue;
import org.fossnova.json.stream.JsonWriter;
import com.fossnova.json.stream.JsonWriterImpl;
/**
* @author <a href="mailto:opalka dot richard at gmail dot com">Richard Opalka</a>
*/
-abstract class JsonStructureImpl implements JsonStructure {
+abstract class JsonStructureImpl implements JsonValue {
public final void writeTo( final JsonWriter jsonWriter ) throws IOException {
if ( jsonWriter == null ) {
@@ -33,7 +33,6 @@
import org.fossnova.json.JsonNumber;
import org.fossnova.json.JsonObject;
import org.fossnova.json.JsonString;
-import org.fossnova.json.JsonStructure;
import org.fossnova.json.JsonValue;
import org.fossnova.json.stream.JsonReader;
import org.fossnova.json.stream.JsonStreamFactory;
@@ -99,21 +98,35 @@ public void roundTrip() throws IOException {
assertRoundTrip( COMPLEX_OBJECT );
}
- private static void assertRoundTrip( final JsonStructure jsonStructure ) throws IOException {
- final String serializedJson = serializeJson( jsonStructure );
- final JsonStructure deserializedJson = deserializeJson( serializedJson );
- assertEquals( jsonStructure, deserializedJson );
+ private static void assertRoundTrip( final JsonObject jsonObject ) throws IOException {
+ final String serializedJsonObject = serializeJson( jsonObject );
+ final JsonValue deserializedJsonObject = deserializeJson( serializedJsonObject );
+ assertEquals( jsonObject, deserializedJsonObject );
}
- private static String serializeJson( final JsonStructure jsonStructure ) throws IOException {
+ private static void assertRoundTrip( final JsonArray jsonArray ) throws IOException {
+ final String serializedJsonObject = serializeJson( jsonArray );
+ final JsonValue deserializedJsonObject = deserializeJson( serializedJsonObject );
+ assertEquals( jsonArray, deserializedJsonObject );
+ }
+
+ private static String serializeJson( final JsonObject jsonObject ) throws IOException {
+ final ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ final JsonWriter jsonWriter = JsonStreamFactory.newInstance().newJsonWriter( baos );
+ jsonObject.writeTo( jsonWriter );
+ jsonWriter.close();
+ return new String( baos.toByteArray() );
+ }
+
+ private static String serializeJson( final JsonArray jsonArray ) throws IOException {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final JsonWriter jsonWriter = JsonStreamFactory.newInstance().newJsonWriter( baos );
- jsonStructure.writeTo( jsonWriter );
+ jsonArray.writeTo( jsonWriter );
jsonWriter.close();
return new String( baos.toByteArray() );
}
- private static JsonStructure deserializeJson( final String jsonString ) throws IOException {
+ private static JsonValue deserializeJson( final String jsonString ) throws IOException {
final ByteArrayInputStream bais = new ByteArrayInputStream( jsonString.getBytes() );
final JsonReader jsonReader = JsonStreamFactory.newInstance().newJsonReader( bais );
final JsonFactory jsonFactory = JsonFactory.newInstance();

0 comments on commit 522d9e1

Please sign in to comment.