Skip to content

Commit

Permalink
adding ability for JSON Handler to take in string representation of J…
Browse files Browse the repository at this point in the history
…SON and create appropriate model element.
  • Loading branch information
mnjuhn committed Mar 7, 2013
1 parent aa9e209 commit 7d7348f
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions src/main/java/edu/berkeley/path/model_elements/JsonHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ public static <T extends GenericContainer> void writeToFile(T obj, String filena
*/
public static <T extends GenericContainer> T readFromFile(Schema schema, String filename) throws IOException {

System.out.println("**** THIS function : readFromFile in file jasonHandler.java is DEPRECATED! ****");

Schema schemaForReading = getDerivedSchema(schema);

DatumReader<T> reader = new SpecificDatumReader<T>(schemaForReading);
Expand All @@ -102,30 +104,23 @@ public static <T extends GenericContainer> T readFromFile(Schema schema, String


/**
* Read model elements Freeway config from VIA
* Read model elements Freeway config from string passed
* @param <T> Model elements type read, e.g. Network or Link
* @param schema Avro schema. Should be T.SCHEMA$
* @param dbString db string from the database
* @param jsonString JSON string from the database
* @return Model elements object of type T
* @throws IOException
*/
public static <T extends GenericContainer> T readFromDBStream(Schema schema, String dbString) throws IOException {

System.out.println("**** THIS function : readFromDBStream in file jasonHandler.java is DEPRECATED! ****");
public static <T extends GenericContainer> T readFromString(Schema schema, String jsonString) throws IOException {

Schema schemaForReading = getDerivedSchema(schema);

DatumReader<T> reader = new SpecificDatumReader<T>(schemaForReading);

String fileContents = dbString ;

fileContents = fileContents.replaceAll("\"edu.berkeley.path.model_elements_base.", "\"edu.berkeley.path.model_elements.");
Decoder decoder = new DecoderFactory().jsonDecoder(schemaForReading, IOUtils.toInputStream(fileContents));
Decoder decoder = new DecoderFactory().jsonDecoder(schemaForReading, jsonString);

T obj = reader.read(null, decoder);

return(obj);

}


Expand Down

0 comments on commit 7d7348f

Please sign in to comment.