News for hackers. Stuff that matters.
Re:Why isn't Java used for modern web application development? by swah on Sunday June 10, 2012 @10:27AM (#4091127)
I'm kinda testing the same setup. There are a couple nice things, but one thing that hurts me coming from Python is that in Python an SQL row was just an dict with data, and I could change my schema (and add/remove entries from this object) and then return it as JSON quite easily.

Now in Java/Dropwizard the tendency is to map from SQL rows to objects, then from objects to JSON. Which is a PITA, even more when your design/database changes too much. (The upside is that when you get some object, the data IS there).

Re:Why isn't Java used for modern web application development? by fizx on Sunday June 10, 2012 @05:21PM (#4092253)
I tend to work more with document-like stores than SQL these days, so there may be more idiomatic solutions....

If you're complaining about having to update the fields in your object, I think thats kinda silly. You bought into the idea of static typing at some point, and now your data has type constraints. If you need need need flexibility you can of course make some field a Map<String, Object>.

If you're complaining about boilerplate, you can at least automate the mapping with code like:

    class Util {
      public static <T> T resultSetToObject(ResultSet rs, Class<T> klass) {
        List<Map<String, Object>> rows = new ArrayList<Map<String, Object>>();
        ResultSetMetaData metaData = resultSet.getMetaData();
        int columnCount = metaData.getColumnCount();

        while (resultSet.next()) {
          Map<String, Object> columns = new LinkedHashMap<String, Object>();

          for (int i = 1; i <= columnCount; i++) {
            columns.put(metaData.getColumnLabel(i), resultSet.getObject(i));
          }

          rows.add(columns);
        }
    
        return new ObjectMapper().convertValue(rows, klass)
      }
    }
Re:Why isn't Java used for modern web application development? by swah on Monday June 11, 2012 @10:09AM (#4094640)
Yes, I wrote something similar (a Rowmap object)... But I have to admit it took me a while to realize that I could break that pattern.