@Test public void readAppleUserAgentJsonFile() throws JsonMappingException, JsonParseException, RuntimeException { JsonToClassConverter converter = new JsonToClassConverter(); HashMap<String, Schema> map = converter.construct("org.wikimedia.analytics.kraken.schemas.AppleUserAgent", "ios.json", "getProduct"); assertEquals(map.keySet().size(), 89); }
public final HashMap<String, Schema> construct(final String className, final String file, final String key) throws JsonMappingException, JsonParseException { JsonFactory jfactory = new JsonFactory(); HashMap<String, Schema> map = new HashMap<String, Schema>(); List<Schema> schemas = null; InputStream input; JavaType type; ObjectMapper mapper = new ObjectMapper(); try { Schema schema = (Schema) Schema.class .getClassLoader() .loadClass(className) .newInstance(); input = schema.getClass().getClassLoader().getResourceAsStream(file); type = mapper.getTypeFactory(). constructCollectionType(List.class, schema.getClass()); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } catch (InstantiationException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } try { JsonParser jParser = jfactory.createJsonParser(input); schemas = mapper.readValue(jParser, type); } catch (IOException e) { System.err.println("Specified file could not be found."); } finally { try { if (input != null) { input.close(); } } catch (IOException e){ System.err.println("Could not close filestream"); } } if (schemas != null){ for (Schema schemaInstance: schemas) { try { Method getKey = schemaInstance.getClass().getMethod(key); map.put(getKey.invoke(schemaInstance).toString(), schemaInstance); } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (InvocationTargetException e) { throw new RuntimeException(e); } catch (NoSuchMethodException e) { System.err.println("Specified key is not a valid Getter for " + className); } } } return map; }
JsonToClassConverter { public final HashMap<String, Schema> construct(final String className, final String file, final String key) throws JsonMappingException, JsonParseException { JsonFactory jfactory = new JsonFactory(); HashMap<String, Schema> map = new HashMap<String, Schema>(); List<Schema> schemas = null; InputStream input; JavaType type; ObjectMapper mapper = new ObjectMapper(); try { Schema schema = (Schema) Schema.class .getClassLoader() .loadClass(className) .newInstance(); input = schema.getClass().getClassLoader().getResourceAsStream(file); type = mapper.getTypeFactory(). constructCollectionType(List.class, schema.getClass()); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } catch (InstantiationException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } try { JsonParser jParser = jfactory.createJsonParser(input); schemas = mapper.readValue(jParser, type); } catch (IOException e) { System.err.println("Specified file could not be found."); } finally { try { if (input != null) { input.close(); } } catch (IOException e){ System.err.println("Could not close filestream"); } } if (schemas != null){ for (Schema schemaInstance: schemas) { try { Method getKey = schemaInstance.getClass().getMethod(key); map.put(getKey.invoke(schemaInstance).toString(), schemaInstance); } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (InvocationTargetException e) { throw new RuntimeException(e); } catch (NoSuchMethodException e) { System.err.println("Specified key is not a valid Getter for " + className); } } } return map; } }
JsonToClassConverter { public final HashMap<String, Schema> construct(final String className, final String file, final String key) throws JsonMappingException, JsonParseException { JsonFactory jfactory = new JsonFactory(); HashMap<String, Schema> map = new HashMap<String, Schema>(); List<Schema> schemas = null; InputStream input; JavaType type; ObjectMapper mapper = new ObjectMapper(); try { Schema schema = (Schema) Schema.class .getClassLoader() .loadClass(className) .newInstance(); input = schema.getClass().getClassLoader().getResourceAsStream(file); type = mapper.getTypeFactory(). constructCollectionType(List.class, schema.getClass()); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } catch (InstantiationException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } try { JsonParser jParser = jfactory.createJsonParser(input); schemas = mapper.readValue(jParser, type); } catch (IOException e) { System.err.println("Specified file could not be found."); } finally { try { if (input != null) { input.close(); } } catch (IOException e){ System.err.println("Could not close filestream"); } } if (schemas != null){ for (Schema schemaInstance: schemas) { try { Method getKey = schemaInstance.getClass().getMethod(key); map.put(getKey.invoke(schemaInstance).toString(), schemaInstance); } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (InvocationTargetException e) { throw new RuntimeException(e); } catch (NoSuchMethodException e) { System.err.println("Specified key is not a valid Getter for " + className); } } } return map; }  }
JsonToClassConverter { public final HashMap<String, Schema> construct(final String className, final String file, final String key) throws JsonMappingException, JsonParseException { JsonFactory jfactory = new JsonFactory(); HashMap<String, Schema> map = new HashMap<String, Schema>(); List<Schema> schemas = null; InputStream input; JavaType type; ObjectMapper mapper = new ObjectMapper(); try { Schema schema = (Schema) Schema.class .getClassLoader() .loadClass(className) .newInstance(); input = schema.getClass().getClassLoader().getResourceAsStream(file); type = mapper.getTypeFactory(). constructCollectionType(List.class, schema.getClass()); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } catch (InstantiationException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } try { JsonParser jParser = jfactory.createJsonParser(input); schemas = mapper.readValue(jParser, type); } catch (IOException e) { System.err.println("Specified file could not be found."); } finally { try { if (input != null) { input.close(); } } catch (IOException e){ System.err.println("Could not close filestream"); } } if (schemas != null){ for (Schema schemaInstance: schemas) { try { Method getKey = schemaInstance.getClass().getMethod(key); map.put(getKey.invoke(schemaInstance).toString(), schemaInstance); } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (InvocationTargetException e) { throw new RuntimeException(e); } catch (NoSuchMethodException e) { System.err.println("Specified key is not a valid Getter for " + className); } } } return map; }  final HashMap<String, Schema> construct(final String className, final String file, final String key); }
JsonToClassConverter { public final HashMap<String, Schema> construct(final String className, final String file, final String key) throws JsonMappingException, JsonParseException { JsonFactory jfactory = new JsonFactory(); HashMap<String, Schema> map = new HashMap<String, Schema>(); List<Schema> schemas = null; InputStream input; JavaType type; ObjectMapper mapper = new ObjectMapper(); try { Schema schema = (Schema) Schema.class .getClassLoader() .loadClass(className) .newInstance(); input = schema.getClass().getClassLoader().getResourceAsStream(file); type = mapper.getTypeFactory(). constructCollectionType(List.class, schema.getClass()); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } catch (InstantiationException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } try { JsonParser jParser = jfactory.createJsonParser(input); schemas = mapper.readValue(jParser, type); } catch (IOException e) { System.err.println("Specified file could not be found."); } finally { try { if (input != null) { input.close(); } } catch (IOException e){ System.err.println("Could not close filestream"); } } if (schemas != null){ for (Schema schemaInstance: schemas) { try { Method getKey = schemaInstance.getClass().getMethod(key); map.put(getKey.invoke(schemaInstance).toString(), schemaInstance); } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (InvocationTargetException e) { throw new RuntimeException(e); } catch (NoSuchMethodException e) { System.err.println("Specified key is not a valid Getter for " + className); } } } return map; }  final HashMap<String, Schema> construct(final String className, final String file, final String key);  }