public static class RecBean{ public String f1; public String f2; public String f3; } @Test public void testObjectAccess() throws Exception{ TransJdbcTemplate lvTj = ContextHolder.getTransJdbcTemplate(); Exception lvException= lvTj.doTransactionBatch(new TransCallback() { @Override public void onExecute(JdbcTemplate pvJt, NamedParameterJdbcTemplate pvNamedJt) throws Exception { List<Map<String,Object>> lvRet=pvJt.queryForList("select *,row_to_json(row(f96_line,f96_order,f96_station)) as rec from v96_qcdet_bylinejob where f96_date='24/Mar/2018'"); PGobject lvObj =(PGobject) lvRet.get(0).get("rec"); String lvVal=lvObj.getValue(); RecBean lvRec=JsonUtils.readValue(lvVal, new TypeReference<RecBean>() { }); Assert.assertNotNull(lvRec.f1); } }); if (lvException!=null) throw lvException; }
还是用PGObject这个通用的类型来接收json的raw data(string类型), 然后通过JsonUtil转换为RecBean类型的对象 .